[PATCH: For next 1/2] ARM: am33xx: Add a function to retrieve the reset reason
Wadim Egorov
w.egorov at phytec.de
Mon Feb 9 07:01:46 PST 2015
This patch adds a function to retrieve the last occurred reset reason
on the AM335x.
Signed-off-by: Wadim Egorov <w.egorov at phytec.de>
---
arch/arm/mach-omap/am33xx_generic.c | 41 ++++++++++++++++++++++++
arch/arm/mach-omap/include/mach/am33xx-generic.h | 13 ++++++++
arch/arm/mach-omap/include/mach/am33xx-silicon.h | 1 +
3 files changed, 55 insertions(+)
diff --git a/arch/arm/mach-omap/am33xx_generic.c b/arch/arm/mach-omap/am33xx_generic.c
index 912138d..ceafc09 100644
--- a/arch/arm/mach-omap/am33xx_generic.c
+++ b/arch/arm/mach-omap/am33xx_generic.c
@@ -476,3 +476,44 @@ int am33xx_of_register_bootdevice(void)
return 0;
}
+
+static const char *resetreason_str[] = {
+ [AM33XX_RESET_ICEPICK] = "IcePick",
+ [AM33XX_RESET_EXTWARM] = "External warm",
+ [AM33XX_RESET_WD1] = "Watchdog1 timer",
+ [AM33XX_RESET_WD0] = "Watchdog0 timer",
+ [AM33XX_RESET_GLOBALSW] = "Global warm software",
+ [AM33XX_RESET_COLD] = "Power-on (cold)",
+ [AM33XX_RESET_UNKNOWN] = "Unknown",
+};
+
+const char *am33xx_get_reset_reason_str(void)
+{
+ return resetreason_str[am33xx_get_reset_reason()];
+}
+
+enum am33xx_resetreason am33xx_get_reset_reason(void)
+{
+ static int init;
+ static uint32_t val;
+
+ if (!init) {
+ /* save value of AM33XX_PRM_RSTST register */
+ val = readl(AM33XX_PRM_RSTST);
+ /* clear AM33XX_PRM_RSTST - must be cleared by software
+ * (warm reset insensitive) */
+ writel(val, AM33XX_PRM_RSTST);
+ init = 1;
+ }
+
+ switch (val) {
+ case (1 << 9): return AM33XX_RESET_ICEPICK;
+ case (1 << 5): return AM33XX_RESET_EXTWARM;
+ case (1 << 4): return AM33XX_RESET_WD1;
+ case (1 << 3): return AM33XX_RESET_WD0;
+ case (1 << 1): return AM33XX_RESET_GLOBALSW;
+ case (1 << 0): return AM33XX_RESET_COLD;
+ }
+
+ return AM33XX_RESET_UNKNOWN;
+}
diff --git a/arch/arm/mach-omap/include/mach/am33xx-generic.h b/arch/arm/mach-omap/include/mach/am33xx-generic.h
index 03418b0..18ca6e7 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-generic.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-generic.h
@@ -36,4 +36,17 @@ int am33xx_devices_init(void);
void am33xx_select_rmii2_crs_dv(void);
int am33xx_of_register_bootdevice(void);
+enum am33xx_resetreason {
+ AM33XX_RESET_ICEPICK,
+ AM33XX_RESET_EXTWARM,
+ AM33XX_RESET_WD1,
+ AM33XX_RESET_WD0,
+ AM33XX_RESET_GLOBALSW,
+ AM33XX_RESET_COLD,
+ AM33XX_RESET_UNKNOWN,
+};
+
+enum am33xx_resetreason am33xx_get_reset_reason(void);
+const char *am33xx_get_reset_reason_str(void);
+
#endif /* __MACH_AM33XX_GENERIC_H */
diff --git a/arch/arm/mach-omap/include/mach/am33xx-silicon.h b/arch/arm/mach-omap/include/mach/am33xx-silicon.h
index 4e63b43..7c209ec 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-silicon.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-silicon.h
@@ -68,6 +68,7 @@
#define AM33XX_PRM_RSTCTRL (AM33XX_PRM_BASE + 0x0f00)
#define AM33XX_PRM_RSTCTRL_RESET 0x1
+#define AM33XX_PRM_RSTST (AM33XX_PRM_BASE + 0x0f08)
/* CTRL */
#define AM33XX_CTRL_BASE (AM33XX_L4_WKUP_BASE + 0x210000)
--
1.9.1
More information about the barebox
mailing list