From: Alexander Sverdlin <[email protected]>

Both existing implementations of get_reset_reason() for K3 cannot be called
twice because they clear the HW register carrying the reset reason
information. Make it possible to call get_reset_reason() multiple times by
saving the reset reason in struct arch_global_data.

Up to now this wasn't an issue, because the functions were called just once
to print the reset source to the console, but it's required to save the
reset reason into the device tree in the following patches.

Clearing the RST_SRC register is simplified at the same time so that the
overall nesting in the code doesn't grow. Writing 0 to the register is NOP
anyway.

Signed-off-by: Alexander Sverdlin <[email protected]>
---
 arch/arm/include/asm/global_data.h |  3 +++
 arch/arm/mach-k3/am62x/boot.c      | 12 +++++++++---
 arch/arm/mach-k3/am64x/boot.c      | 12 +++++++++---
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/arch/arm/include/asm/global_data.h 
b/arch/arm/include/asm/global_data.h
index b2ec450f900..c2b20a1dde6 100644
--- a/arch/arm/include/asm/global_data.h
+++ b/arch/arm/include/asm/global_data.h
@@ -105,6 +105,9 @@ struct arch_global_data {
 #ifdef CONFIG_ARCH_IMX8ULP
        bool m33_handshake_done;
 #endif
+#ifdef CONFIG_ARCH_K3
+       u32 reset_src;                  /* Cached reset source register */
+#endif
 #ifdef CONFIG_SMBIOS
        ulong smbios_start;             /* Start address of SMBIOS table */
 #endif
diff --git a/arch/arm/mach-k3/am62x/boot.c b/arch/arm/mach-k3/am62x/boot.c
index a3a6cda6bdb..bae53f1e459 100644
--- a/arch/arm/mach-k3/am62x/boot.c
+++ b/arch/arm/mach-k3/am62x/boot.c
@@ -1,8 +1,11 @@
 // SPDX-License-Identifier: GPL-2.0+
+#include <asm/global_data.h>
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
 #include <asm/arch/am62_spl.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 static u32 __get_backup_bootmedia(u32 devstat)
 {
        u32 bkup_bootmode = (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
@@ -104,11 +107,14 @@ u32 get_boot_device(void)
 
 const char *get_reset_reason(void)
 {
-       u32 reset_reason = readl(CTRLMMR_MCU_RST_SRC);
+       u32 reset_reason = gd->arch.reset_src;
 
-       /* After reading reset source register, software must clear it */
-       if (reset_reason)
+       if (!reset_reason) {
+               reset_reason = readl(CTRLMMR_MCU_RST_SRC);
+               /* After reading reset source register, software must clear it 
*/
                writel(reset_reason, CTRLMMR_MCU_RST_SRC);
+               gd->arch.reset_src = reset_reason;
+       }
 
        if (reset_reason == 0 ||
           (reset_reason & (RST_SRC_SW_MAIN_POR_FROM_MAIN |
diff --git a/arch/arm/mach-k3/am64x/boot.c b/arch/arm/mach-k3/am64x/boot.c
index bf8e1a5cb44..a5a6fe2659c 100644
--- a/arch/arm/mach-k3/am64x/boot.c
+++ b/arch/arm/mach-k3/am64x/boot.c
@@ -1,8 +1,11 @@
 // SPDX-License-Identifier: GPL-2.0+
+#include <asm/global_data.h>
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
 #include <asm/arch/spl.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 static u32 __get_backup_bootmedia(u32 main_devstat)
 {
        u32 bkup_bootmode =
@@ -106,11 +109,14 @@ u32 get_boot_device(void)
 
 const char *get_reset_reason(void)
 {
-       u32 reset_reason = readl(CTRLMMR_MCU_RST_SRC);
+       u32 reset_reason = gd->arch.reset_src;
 
-       /* After reading reset source register, software must clear it */
-       if (reset_reason)
+       if (!reset_reason) {
+               reset_reason = readl(CTRLMMR_MCU_RST_SRC);
+               /* After reading reset source register, software must clear it 
*/
                writel(reset_reason, CTRLMMR_MCU_RST_SRC);
+               gd->arch.reset_src = reset_reason;
+       }
 
        if (reset_reason == 0 ||
            (reset_reason & (RST_SRC_SW_MAIN_POR_FROM_MAIN |
-- 
2.52.0

Reply via email to