blob: 805b28af8e4df43b05040e7adbb724f9baefffc6 [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>
Aniket Limayee778e742024-11-19 06:02:58 +053022#include <k3-avs.h>
Lokesh Vutlaa2285322019-06-13 10:29:42 +053023
Andrew Davis336b0792024-05-10 15:21:24 -050024#include "../sysfw-loader.h"
25#include "../common.h"
26
Jayesh Choudhary3aa50582024-06-14 18:14:37 +053027/* NAVSS North Bridge (NB) registers */
28#define NAVSS0_NBSS_NB0_CFG_MMRS 0x03802000
29#define NAVSS0_NBSS_NB1_CFG_MMRS 0x03803000
30#define NAVSS0_NBSS_NB0_CFG_NB_THREADMAP (NAVSS0_NBSS_NB0_CFG_MMRS + 0x10)
31#define NAVSS0_NBSS_NB1_CFG_NB_THREADMAP (NAVSS0_NBSS_NB1_CFG_MMRS + 0x10)
32/*
33 * Thread Map for North Bridge Configuration
34 * Each bit is for each VBUSM source.
35 * Bit[0] maps orderID 0-7 to VBUSM.C thread number
36 * Bit[1] maps orderID 8-15 to VBUSM.C thread number
37 * When bit has value 0: VBUSM.C thread 0 (non-real time traffic)
38 * When bit has value 1: VBUSM.C thread 2 (real time traffic)
39 */
40#define NB_THREADMAP_BIT0 BIT(0)
41#define NB_THREADMAP_BIT1 BIT(1)
42
Aniket Limayee778e742024-11-19 06:02:58 +053043/* TISCI DEV ID for A72, MSMC Clock */
44#define DEV_A72SS0_CORE0_0_ID 202
45#define DEV_A72SS0_CORE0_0_ARM_CLK_CLK_ID 2
46#define DEV_A72SS0_CORE0_ID 4
47#define DEV_A72SS0_CORE0_MSMC_CLK_ID 1
48
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050049#ifdef CONFIG_K3_LOAD_SYSFW
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050050struct fwl_data cbass_hc_cfg0_fwls[] = {
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053051#if defined(CONFIG_TARGET_J721E_R5_EVM)
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050052 { "PCIE0_CFG", 2560, 8 },
53 { "PCIE1_CFG", 2561, 8 },
54 { "USB3SS0_CORE", 2568, 4 },
55 { "USB3SS1_CORE", 2570, 4 },
56 { "EMMC8SS0_CFG", 2576, 4 },
57 { "UFS_HCI0_CFG", 2580, 4 },
58 { "SERDES0", 2584, 1 },
59 { "SERDES1", 2585, 1 },
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053060#elif defined(CONFIG_TARGET_J7200_R5_EVM)
61 { "PCIE1_CFG", 2561, 7 },
62#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050063}, cbass_hc0_fwls[] = {
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053064#if defined(CONFIG_TARGET_J721E_R5_EVM)
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050065 { "PCIE0_HP", 2528, 24 },
66 { "PCIE0_LP", 2529, 24 },
67 { "PCIE1_HP", 2530, 24 },
68 { "PCIE1_LP", 2531, 24 },
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053069#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050070}, cbass_rc_cfg0_fwls[] = {
71 { "EMMCSD4SS0_CFG", 2380, 4 },
72}, cbass_rc0_fwls[] = {
73 { "GPMC0", 2310, 8 },
74}, infra_cbass0_fwls[] = {
75 { "PLL_MMR0", 8, 26 },
76 { "CTRL_MMR0", 9, 16 },
77}, mcu_cbass0_fwls[] = {
78 { "MCU_R5FSS0_CORE0", 1024, 4 },
79 { "MCU_R5FSS0_CORE0_CFG", 1025, 2 },
80 { "MCU_R5FSS0_CORE1", 1028, 4 },
81 { "MCU_FSS0_CFG", 1032, 12 },
82 { "MCU_FSS0_S1", 1033, 8 },
83 { "MCU_FSS0_S0", 1036, 8 },
84 { "MCU_PSROM49152X32", 1048, 1 },
85 { "MCU_MSRAM128KX64", 1050, 8 },
86 { "MCU_CTRL_MMR0", 1200, 8 },
87 { "MCU_PLL_MMR0", 1201, 3 },
88 { "MCU_CPSW0", 1220, 2 },
89}, wkup_cbass0_fwls[] = {
90 { "WKUP_CTRL_MMR0", 131, 16 },
91};
92#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050093
Andreas Dannenberg660aa462019-06-13 10:29:44 +053094static void ctrl_mmr_unlock(void)
95{
96 /* Unlock all WKUP_CTRL_MMR0 module registers */
97 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
98 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
99 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
100 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
101 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
102 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
103 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
104
105 /* Unlock all MCU_CTRL_MMR0 module registers */
106 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
107 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
108 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
109 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
110 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
111
112 /* Unlock all CTRL_MMR0 module registers */
113 mmr_unlock(CTRL_MMR0_BASE, 0);
114 mmr_unlock(CTRL_MMR0_BASE, 1);
115 mmr_unlock(CTRL_MMR0_BASE, 2);
116 mmr_unlock(CTRL_MMR0_BASE, 3);
Andreas Dannenberg660aa462019-06-13 10:29:44 +0530117 mmr_unlock(CTRL_MMR0_BASE, 5);
Lokesh Vutlad5bc6862020-08-05 22:44:20 +0530118 if (soc_is_j721e())
119 mmr_unlock(CTRL_MMR0_BASE, 6);
Andreas Dannenberg660aa462019-06-13 10:29:44 +0530120 mmr_unlock(CTRL_MMR0_BASE, 7);
121}
122
Faiz Abbas68393212020-02-26 13:44:36 +0530123#if defined(CONFIG_K3_LOAD_SYSFW)
124void k3_mmc_stop_clock(void)
125{
126 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
127 struct mmc *mmc = find_mmc_device(0);
128
129 if (!mmc)
130 return;
131
132 mmc->saved_clock = mmc->clock;
133 mmc_set_clock(mmc, 0, true);
134 }
135}
136
137void k3_mmc_restart_clock(void)
138{
139 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
140 struct mmc *mmc = find_mmc_device(0);
141
142 if (!mmc)
143 return;
144
145 mmc_set_clock(mmc, mmc->saved_clock, false);
146 }
147}
148#endif
149
Jayesh Choudhary3aa50582024-06-14 18:14:37 +0530150/* Setup North Bridge registers to map ORDERID 8-15 to RT traffic */
151static void setup_navss_nb(void)
152{
153 writel(NB_THREADMAP_BIT1, (uintptr_t)NAVSS0_NBSS_NB0_CFG_NB_THREADMAP);
154 writel(NB_THREADMAP_BIT1, (uintptr_t)NAVSS0_NBSS_NB1_CFG_NB_THREADMAP);
155}
156
Aniket Limayee778e742024-11-19 06:02:58 +0530157#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
158static int get_clock_index_by_dev_id(ofnode node, u32 dev_id, u32 clk_id)
159{
160 ofnode clknode;
161 int count, i;
162 struct ofnode_phandle_args phandle_args;
163
164 clknode = ofnode_by_compatible(ofnode_null(), "ti,k2g-sci-clk");
165 if (!ofnode_valid(clknode)) {
166 printf("%s: clock-controller not found\n", __func__);
167 return -ENODEV;
168 }
169
170 count = ofnode_count_phandle_with_args(node, "assigned-clocks", "#clock-cells", 0);
171 for (i = 0; i < count; i++) {
172 if (ofnode_parse_phandle_with_args(node, "assigned-clocks",
173 "#clock-cells", 0, i, &phandle_args)) {
174 printf("%s: Could not parse assigned-clocks at index %d\n", __func__, i);
175 continue;
176 }
177 if (ofnode_equal(clknode, phandle_args.node) &&
178 phandle_args.args[0] == dev_id && phandle_args.args[1] == clk_id)
179 return i;
180 }
181 return -1;
182}
183
184static int fdt_fixup_a72ss_clock_frequency(void)
185{
186 int index, size;
187 u32 *rates;
188 ofnode node;
189
190 node = ofnode_by_compatible(ofnode_null(), "ti,am654-rproc");
191 if (!ofnode_valid(node)) {
192 printf("%s: A72 not found\n", __func__);
193 return -ENODEV;
194 }
195
196 rates = fdt_getprop_w(ofnode_to_fdt(node), ofnode_to_offset(node),
197 "assigned-clock-rates", &size);
198 if (!rates) {
199 printf("%s: Wrong A72 assigned-clocks-rates configuration\n", __func__);
200 return -1;
201 }
202
203 /* Update A72 Clock Frequency to OPP_LOW spec */
204 index = get_clock_index_by_dev_id(node,
205 DEV_A72SS0_CORE0_0_ID,
206 DEV_A72SS0_CORE0_0_ARM_CLK_CLK_ID);
207 if (index < 0 || index >= (size / sizeof(u32))) {
208 printf("%s: Wrong A72 assigned-clocks configuration\n", __func__);
209 return -1;
210 }
211 rates[index] = cpu_to_fdt32(1000000000);
212 printf("Changed A72 CPU frequency to %dHz in DT\n", 1000000000);
213
214 /* Update MSMC Clock Frequency to OPP_LOW spec */
215 index = get_clock_index_by_dev_id(node,
216 DEV_A72SS0_CORE0_ID,
217 DEV_A72SS0_CORE0_MSMC_CLK_ID);
218 if (index < 0 || index >= (size / sizeof(u32))) {
219 printf("%s: Wrong A72 assigned-clocks configuration\n", __func__);
220 return -1;
221 }
222 rates[index] = cpu_to_fdt32(500000000);
223 printf("Changed MSMC frequency to %dHz in DT\n", 500000000);
224
225 return 0;
226}
227#endif
228
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530229/*
230 * This uninitialized global variable would normal end up in the .bss section,
231 * but the .bss is cleared between writing and reading this variable, so move
232 * it to the .data section.
233 */
Marek Behún4bebdd32021-05-20 13:23:52 +0200234u32 bootindex __section(".data");
235static struct rom_extended_boot_data bootdata __section(".data");
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530236
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530237static void store_boot_info_from_rom(void)
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530238{
239 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Bryan Brattlof270537c2022-11-22 13:28:11 -0600240 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530241 sizeof(struct rom_extended_boot_data));
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530242}
243
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530244#ifdef CONFIG_SPL_OF_LIST
245void do_dt_magic(void)
246{
247 int ret, rescan, mmc_dev = -1;
248 static struct mmc *mmc;
249
Andrew Davis2dde9a72023-04-06 11:38:17 -0500250 /* Perform board detection */
251 do_board_detect();
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530252
253 /*
254 * Board detection has been done.
255 * Let us see if another dtb wouldn't be a better match
256 * for our board
257 */
258 if (IS_ENABLED(CONFIG_CPU_V7R)) {
259 ret = fdtdec_resetup(&rescan);
260 if (!ret && rescan) {
261 dm_uninit();
262 dm_init_and_scan(true);
263 }
264 }
265
266 /*
267 * Because of multi DTB configuration, the MMC device has
268 * to be re-initialized after reconfiguring FDT inorder to
269 * boot from MMC. Do this when boot mode is MMC and ROM has
270 * not loaded SYSFW.
271 */
272 switch (spl_boot_device()) {
273 case BOOT_DEVICE_MMC1:
274 mmc_dev = 0;
275 break;
276 case BOOT_DEVICE_MMC2:
277 case BOOT_DEVICE_MMC2_2:
278 mmc_dev = 1;
279 break;
280 }
281
282 if (mmc_dev > 0 && !is_rom_loaded_sysfw(&bootdata)) {
283 ret = mmc_init_device(mmc_dev);
284 if (!ret) {
285 mmc = find_mmc_device(mmc_dev);
286 if (mmc) {
287 ret = mmc_init(mmc);
288 if (ret) {
289 printf("mmc init failed with error: %d\n", ret);
290 }
291 }
292 }
293 }
294}
295#endif
296
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530297void board_init_f(ulong dummy)
298{
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530299#if defined(CONFIG_K3_J721E_DDRSS) || defined(CONFIG_K3_LOAD_SYSFW)
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530300 struct udevice *dev;
301 int ret;
302#endif
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530303 /*
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530304 * Cannot delay this further as there is a chance that
305 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530306 */
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530307 store_boot_info_from_rom();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530308
Andreas Dannenberg660aa462019-06-13 10:29:44 +0530309 /* Make all control module registers accessible */
310 ctrl_mmr_unlock();
311
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530312#ifdef CONFIG_CPU_V7R
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +0530313 disable_linefill_optimization();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530314 setup_k3_mpu_regions();
315#endif
316
317 /* Init DM early */
318 spl_early_init();
319
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530320#ifdef CONFIG_K3_LOAD_SYSFW
321 /*
322 * Process pinctrl for the serial0 a.k.a. MCU_UART0 module and continue
323 * regardless of the result of pinctrl. Do this without probing the
324 * device, but instead by searching the device that would request the
325 * given sequence number if probed. The UART will be used by the system
326 * firmware (SYSFW) image for various purposes and SYSFW depends on us
327 * to initialize its pin settings.
328 */
Simon Glass07e13382020-12-16 21:20:29 -0700329 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530330 if (!ret)
331 pinctrl_select_state(dev, "default");
332
333 /*
Neha Malcom Francis0e15b1f2023-09-27 18:39:52 +0530334 * Force probe of clk_k3 driver here to ensure basic default clock
335 * configuration is always done.
336 */
337 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
338 ret = uclass_get_device_by_driver(UCLASS_CLK,
339 DM_DRIVER_GET(ti_clk),
340 &dev);
341 if (ret)
342 panic("Failed to initialize clk-k3!\n");
343 }
344
345 /*
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530346 * Load, start up, and configure system controller firmware. Provide
347 * the U-Boot console init function to the SYSFW post-PM configuration
348 * callback hook, effectively switching on (or over) the console
349 * output.
350 */
Lokesh Vutla8be6bbf2020-08-05 22:44:23 +0530351 k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata),
352 k3_mmc_stop_clock, k3_mmc_restart_clock);
Faiz Abbas68393212020-02-26 13:44:36 +0530353
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530354#ifdef CONFIG_SPL_OF_LIST
355 do_dt_magic();
356#endif
357
Faiz Abbas68393212020-02-26 13:44:36 +0530358 /* Prepare console output */
359 preloader_console_init();
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500360
361 /* Disable ROM configured firewalls right after loading sysfw */
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500362 remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls));
363 remove_fwl_configs(cbass_hc0_fwls, ARRAY_SIZE(cbass_hc0_fwls));
364 remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls));
365 remove_fwl_configs(cbass_rc0_fwls, ARRAY_SIZE(cbass_rc0_fwls));
366 remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls));
367 remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls));
368 remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls));
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530369#else
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530370 /* Prepare console output */
371 preloader_console_init();
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530372#endif
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530373
Lokesh Vutla5fafe442020-03-10 16:50:58 +0530374 /* Output System Firmware version info */
375 k3_sysfw_print_ver();
376
Andrew Davis2dde9a72023-04-06 11:38:17 -0500377 /* Perform board detection */
378 do_board_detect();
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530379
Keerthy0b01f662019-10-24 15:00:53 +0530380#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
Simon Glass65130cd2020-12-28 20:34:56 -0700381 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
Keerthy0b01f662019-10-24 15:00:53 +0530382 &dev);
Aniket Limayee778e742024-11-19 06:02:58 +0530383 if (ret) {
Keerthy0b01f662019-10-24 15:00:53 +0530384 printf("AVS init failed: %d\n", ret);
Aniket Limayee778e742024-11-19 06:02:58 +0530385 } else if (IS_ENABLED(CONFIG_K3_OPP_LOW)) {
386 ret = k3_avs_check_opp(dev, J721E_VDD_MPU, AM6_OPP_LOW);
387 if (ret) {
388 printf("OPP_LOW: k3_avs_check_opp failed: %d\n", ret);
389 } else {
390 ret = fdt_fixup_a72ss_clock_frequency();
391 if (ret)
392 printf("OPP_LOW: fdt_fixup_a72ss_clock_frequency failed: %d\n",
393 ret);
394 }
395 }
Keerthy0b01f662019-10-24 15:00:53 +0530396#endif
397
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530398#if defined(CONFIG_K3_J721E_DDRSS)
399 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
400 if (ret)
401 panic("DRAM init failed: %d\n", ret);
402#endif
Joao Paulo Goncalvesfc3557f2023-11-13 16:07:21 -0300403 spl_enable_cache();
Jayesh Choudhary3aa50582024-06-14 18:14:37 +0530404
405 if (IS_ENABLED(CONFIG_CPU_V7R))
406 setup_navss_nb();
407
408 setup_qos();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530409}
Lokesh Vutla6edde292019-06-13 10:29:43 +0530410
Andre Przywara3cb12ef2021-07-12 11:06:49 +0100411u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
Lokesh Vutla6edde292019-06-13 10:29:43 +0530412{
413 switch (boot_device) {
414 case BOOT_DEVICE_MMC1:
Nishanth Menon0f36a4a2023-11-04 02:21:47 -0500415 if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT)) {
416 if (spl_mmc_emmc_boot_partition(mmc))
417 return MMCSD_MODE_EMMCBOOT;
418 return MMCSD_MODE_FS;
419 }
420 if (IS_ENABLED(CONFIG_SPL_FS_FAT) || IS_ENABLED(CONFIG_SPL_FS_EXT4))
421 return MMCSD_MODE_FS;
422 return MMCSD_MODE_EMMCBOOT;
Lokesh Vutla6edde292019-06-13 10:29:43 +0530423 case BOOT_DEVICE_MMC2:
424 return MMCSD_MODE_FS;
425 default:
426 return MMCSD_MODE_RAW;
427 }
428}
429
Andreas Dannenbergee0f5e62020-05-16 21:05:01 +0530430static u32 __get_backup_bootmedia(u32 main_devstat)
431{
432 u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
433 MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
434
435 switch (bkup_boot) {
436 case BACKUP_BOOT_DEVICE_USB:
437 return BOOT_DEVICE_DFU;
438 case BACKUP_BOOT_DEVICE_UART:
439 return BOOT_DEVICE_UART;
440 case BACKUP_BOOT_DEVICE_ETHERNET:
441 return BOOT_DEVICE_ETHERNET;
442 case BACKUP_BOOT_DEVICE_MMC2:
443 {
444 u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
445 MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
446 if (port == 0x0)
447 return BOOT_DEVICE_MMC1;
448 return BOOT_DEVICE_MMC2;
449 }
450 case BACKUP_BOOT_DEVICE_SPI:
451 return BOOT_DEVICE_SPI;
452 case BACKUP_BOOT_DEVICE_I2C:
453 return BOOT_DEVICE_I2C;
454 }
455
456 return BOOT_DEVICE_RAM;
457}
458
Lokesh Vutla6edde292019-06-13 10:29:43 +0530459static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
460{
461
462 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
463 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
464
465 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
466 BOOT_MODE_B_SHIFT;
467
Jonathan Humphreys9d797682024-02-23 18:23:06 -0600468 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI ||
469 bootmode == BOOT_DEVICE_XSPI)
Lokesh Vutla6edde292019-06-13 10:29:43 +0530470 bootmode = BOOT_DEVICE_SPI;
471
472 if (bootmode == BOOT_DEVICE_MMC2) {
473 u32 port = (main_devstat &
474 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
475 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
476 if (port == 0x0)
477 bootmode = BOOT_DEVICE_MMC1;
478 }
479
480 return bootmode;
481}
482
Vaishnav Achath146b6c12022-06-03 11:32:16 +0530483u32 spl_spi_boot_bus(void)
484{
485 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
486 u32 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
487 u32 bootmode = ((wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
488 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT) |
489 ((main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << BOOT_MODE_B_SHIFT);
490
491 return (bootmode == BOOT_DEVICE_QSPI) ? 1 : 0;
492}
493
Lokesh Vutla6edde292019-06-13 10:29:43 +0530494u32 spl_boot_device(void)
495{
496 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
497 u32 main_devstat;
498
499 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
500 printf("ERROR: MCU only boot is not yet supported\n");
501 return BOOT_DEVICE_RAM;
502 }
503
504 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
505 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
506
Andreas Dannenbergee0f5e62020-05-16 21:05:01 +0530507 if (bootindex == K3_PRIMARY_BOOTMODE)
508 return __get_primary_bootmedia(main_devstat, wkup_devstat);
509 else
510 return __get_backup_bootmedia(main_devstat);
Lokesh Vutla6edde292019-06-13 10:29:43 +0530511}