From 22b548044b840d67bd941c5b66602ae643db21d3 Mon Sep 17 00:00:00 2001
From: Lokesh Vutla <lokeshvutla@ti.com>
Date: Mon, 7 Oct 2019 19:26:38 +0530
Subject: [PATCH] armv7R: K3: j721e: Add support for triggering ddr init from
 SPL

In SPL, DDR should be made available by the end of board_init_f()
so that apis in board_init_r() can use ddr. Adding support for
triggering DDR initialization from board_init_f().

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
---
 arch/arm/mach-k3/j721e_init.c | 8 +++++++-
 board/ti/j721e/Kconfig        | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
index 733e414654..5e3813252b 100644
--- a/arch/arm/mach-k3/j721e_init.c
+++ b/arch/arm/mach-k3/j721e_init.c
@@ -73,7 +73,7 @@ static void store_boot_index_from_rom(void)
 
 void board_init_f(ulong dummy)
 {
-#if defined(CONFIG_K3_LOAD_SYSFW)
+#if defined(CONFIG_K3_J721E_DDRSS) || defined(CONFIG_K3_LOAD_SYSFW)
 	struct udevice *dev;
 	int ret;
 #endif
@@ -117,6 +117,12 @@ void board_init_f(ulong dummy)
 	/* Prepare console output */
 	preloader_console_init();
 #endif
+
+#if defined(CONFIG_K3_J721E_DDRSS)
+	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
+	if (ret)
+		panic("DRAM init failed: %d\n", ret);
+#endif
 }
 
 u32 spl_boot_mode(const u32 boot_device)
diff --git a/board/ti/j721e/Kconfig b/board/ti/j721e/Kconfig
index c2deb6916a..88097df653 100644
--- a/board/ti/j721e/Kconfig
+++ b/board/ti/j721e/Kconfig
@@ -21,6 +21,7 @@ config TARGET_J721E_R5_EVM
 	select K3_LOAD_SYSFW
 	select RAM
 	select SPL_RAM
+	select K3_J721E_DDRSS
 	imply SYS_K3_SPL_ATF
 
 endchoice
-- 
2.39.5