From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] ARM: at91: add at91sam9/sama5 reset reason detection
Date: Mon, 22 Jun 2020 10:42:05 +0200 [thread overview]
Message-ID: <20200622084205.23897-1-a.fatoum@pengutronix.de> (raw)
The reset controller status register contains information about the last
reset's cause. Tell barebox about it.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/mach-at91/at91sam9_rst.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/arch/arm/mach-at91/at91sam9_rst.c b/arch/arm/mach-at91/at91sam9_rst.c
index 8f03576e698f..a61a26936f5a 100644
--- a/arch/arm/mach-at91/at91sam9_rst.c
+++ b/arch/arm/mach-at91/at91sam9_rst.c
@@ -7,14 +7,42 @@
#include <init.h>
#include <io.h>
#include <restart.h>
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <mach/at91_rstc.h>
+#include <reset_source.h>
struct at91sam9x_rst {
struct restart_handler restart;
void __iomem *base;
};
+static int reasons[] = {
+ RESET_POR, /* GENERAL Both VDDCORE and VDDBU rising */
+ RESET_WKE, /* WAKEUP VDDCORE rising */
+ RESET_WDG, /* WATCHDOG Watchdog fault occurred */
+ RESET_RST, /* SOFTWARE Reset required by the software */
+ RESET_EXT, /* USER NRST pin detected low */
+};
+
+static void at91sam9x_set_reset_reason(struct device_d *dev,
+ void __iomem *base)
+{
+ enum reset_src_type type = RESET_UKWN;
+ u32 sr, rsttyp;
+
+ sr = readl(base + AT91_RSTC_SR);
+ rsttyp = FIELD_GET(AT91_RSTC_RSTTYP, sr);
+
+ if (rsttyp < ARRAY_SIZE(reasons))
+ type = reasons[rsttyp];
+
+ dev_info(dev, "reset reason %s (RSTC_SR: 0x%05x)\n",
+ reset_source_to_string(type), sr);
+
+ reset_source_set(type);
+}
+
static void __noreturn at91sam9x_restart_soc(struct restart_handler *rst)
{
struct at91sam9x_rst *priv = container_of(rst, struct at91sam9x_rst, restart);
@@ -52,6 +80,8 @@ static int at91sam9x_rst_probe(struct device_d *dev)
clk_enable(clk);
+ at91sam9x_set_reset_reason(dev, priv->base);
+
priv->restart.name = "at91sam9x-rst";
priv->restart.restart = at91sam9x_restart_soc;
--
2.27.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2020-06-22 8:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-22 8:42 Ahmad Fatoum [this message]
2020-06-23 10:03 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200622084205.23897-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox