Skip to contentSkip to conversation

rockchip: rk3288: Add reset reason detection

PATCH Superseded Wadim Egorov 3 participants 3 messages Jul 18, 2017 – Aug 6, 2017

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rockchip: rk3288: Add reset reason detection

Sometimes it's helpful to know the reset reason caused in the SoC. Add reset reason detection for the RK3288 SoC.
This will set an environemt variable which represents the reset reason.

---
Changes in v2:
- Added Acked-by: Philipp Tomsich <[email protected]>
- Clear cru_glb_rst_st
- POR if cru_glb_rst_st is 0
- RST if 1st or 2nd bit is set
Can be tested with mw 0xff7601b0 0xfffffdb9

                     mw 0xff7601b4 0xffffeca8
---
 arch/arm/mach-rockchip/rk3288-board.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
arch/arm/mach-rockchip/rk3288-board.c +35 -0
index 613967c..da1995c 100644
@@ -11,6 +11,7 @@
 #include <syscon.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
+#include <asm/arch/cru_rk3288.h>
 #include <asm/arch/periph.h>
 #include <asm/arch/pmu_rk3288.h>
 #include <asm/arch/qos_rk3288.h>
@@ -70,10 +71,44 @@ int rk3288_qos_init(void)
 	return 0;
 }
 
+static void rk3288_detect_reset_reason(void)
+{
+	struct rk3288_cru *cru = rockchip_get_cru();
+	if (IS_ERR(cru))
+		return;
+
+	switch (cru->cru_glb_rst_st) {
+	case 0:
+		setenv("reset_reason", "POR");
+		break;
+	case (1 << 0):
+	case (1 << 1):
+		setenv("reset_reason", "RST");
+		break;
+	case (1 << 2):
+	case (1 << 3):
+		setenv("reset_reason", "THERMAL");
+		break;
+	case (1 << 4):
+	case (1 << 5):
+		setenv("reset_reason", "WDOG");
+		break;
+	default:
+		setenv("reset_reason", "unknown reset");
+	}
+
+	/*
+	 * Clear cru_glb_rst_st, so we can determine the last reset cause
+	 * for following resets.
+	 */
+	rk_clrreg(&cru->cru_glb_rst_st, 0x3f);
+}
+
 int board_late_init(void)
 {
 	setup_boot_mode();
 	rk3288_qos_init();
+	rk3288_detect_reset_reason();
 
 	return rk_board_late_init();
 }
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/1 rockchip: rk3288: Add reset reason detection

Quoted 3 lines · Wadim Egorov

Sometimes it's helpful to know the reset reason caused in the SoC. Add reset reason detection for the RK3288 SoC.
This will set an environemt variable which represents the reset reason.

typo: environment

Quoted 34 lines

---
Changes in v2:
- Added Acked-by: Philipp Tomsich <[email protected]>
- Clear cru_glb_rst_st
- POR if cru_glb_rst_st is 0
- RST if 1st or 2nd bit is set
Can be tested with mw 0xff7601b0 0xfffffdb9

                    mw 0xff7601b4 0xffffeca8

---
arch/arm/mach-rockchip/rk3288-board.c | 35 +++++++++++++++++++++++++++++++++++

1 file changed, 35 insertions(+)
arch/arm/mach-rockchip/rk3288-board.c +3 -0
index 613967c..da1995c 100644
@@ -11,6 +11,7 @@
 #include <syscon.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
+#include <asm/arch/cru_rk3288.h>
 #include <asm/arch/periph.h>
 #include <asm/arch/pmu_rk3288.h>
 #include <asm/arch/qos_rk3288.h>
@@ -70,10 +71,44 @@ int rk3288_qos_init(void)
 	return 0;
 }
 
+static void rk3288_detect_reset_reason(void)
+{

arch/arm/mach-rockchip/rk3288-board.c int rk3288_qos_init(void) · line 85

Quoted 10 lines
arch/arm/mach-rockchip/rk3288-board.c +10 -0
+	struct rk3288_cru *cru = rockchip_get_cru();
+	if (IS_ERR(cru))
+		return;
+
+	switch (cru->cru_glb_rst_st) {
+	case 0:
+		setenv("reset_reason", "POR");
+		break;
+	case (1 << 0):
+	case (1 << 1):

Please use symbolic constants (either 'const u32' or enum). Applies to the below ones as well.

Quoted 30 lines
arch/arm/mach-rockchip/rk3288-board.c +22 -0
+		setenv("reset_reason", "RST");
+		break;
+	case (1 << 2):
+	case (1 << 3):
+		setenv("reset_reason", "THERMAL");
+		break;
+	case (1 << 4):
+	case (1 << 5):
+		setenv("reset_reason", "WDOG");
+		break;
+	default:
+		setenv("reset_reason", "unknown reset");
+	}
+
+	/*
+	 * Clear cru_glb_rst_st, so we can determine the last reset cause
+	 * for following resets.
+	 */
+	rk_clrreg(&cru->cru_glb_rst_st, 0x3f);
+}
+
 int board_late_init(void)
 {
 	setup_boot_mode();
 	rk3288_qos_init();
+	rk3288_detect_reset_reason();
 
 	return rk_board_late_init();
 }
#2 lore raw

PATCH v2 1/1 rockchip: rk3288: Add reset reason detection

In reply to Wadim Egorov

Hi,

Quoted 51 lines · Wadim Egorov

Sometimes it's helpful to know the reset reason caused in the SoC. Add reset reason detection for the RK3288 SoC.
This will set an environemt variable which represents the reset reason.

---
Changes in v2:
- Added Acked-by: Philipp Tomsich <[email protected]>
- Clear cru_glb_rst_st
- POR if cru_glb_rst_st is 0
- RST if 1st or 2nd bit is set
Can be tested with mw 0xff7601b0 0xfffffdb9

                     mw 0xff7601b4 0xffffeca8
---
 arch/arm/mach-rockchip/rk3288-board.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
arch/arm/mach-rockchip/rk3288-board.c +16 -0
index 613967c..da1995c 100644
@@ -11,6 +11,7 @@
 #include <syscon.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
+#include <asm/arch/cru_rk3288.h>
 #include <asm/arch/periph.h>
 #include <asm/arch/pmu_rk3288.h>
 #include <asm/arch/qos_rk3288.h>
@@ -70,10 +71,44 @@ int rk3288_qos_init(void)
        return 0;
 }
 
+static void rk3288_detect_reset_reason(void)
+{
+       struct rk3288_cru *cru = rockchip_get_cru();
+       if (IS_ERR(cru))
+               return;
+
+       switch (cru->cru_glb_rst_st) {
+       case 0:
+               setenv("reset_reason", "POR");
+               break;
+       case (1 << 0):
+       case (1 << 1):
+               setenv("reset_reason", "RST");
+               break;
+       case (1 << 2):

arch/arm/mach-rockchip/rk3288-board.c int rk3288_qos_init(void) · line 98

Quoted 10 lines
arch/arm/mach-rockchip/rk3288-board.c +10 -0
+       case (1 << 3):
+               setenv("reset_reason", "THERMAL");
+               break;
+       case (1 << 4):
+       case (1 << 5):
+               setenv("reset_reason", "WDOG");
+               break;
+       default:
+               setenv("reset_reason", "unknown reset");
+       }

Can you factor out the setenv() and put it (once) at the end? Inside the switch() you can set a string var to POR or RST.

Quoted 17 lines
arch/arm/mach-rockchip/rk3288-board.c +9 -1
+
+       /*
+        * Clear cru_glb_rst_st, so we can determine the last reset cause
+        * for following resets.
+        */
+       rk_clrreg(&cru->cru_glb_rst_st, 0x3f);
+}
+
 int board_late_init(void)
 {
        setup_boot_mode();
        rk3288_qos_init();
+       rk3288_detect_reset_reason();
 
        return rk_board_late_init();
 }
--
Quoted 2 lines

1.9.1

Regards,
Simon