From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/2] watchdog: bcm2835: add support for powering off SoC
Date: Tue, 11 Jun 2024 08:58:10 +0200 [thread overview]
Message-ID: <20240611065811.2900029-1-a.fatoum@pengutronix.de> (raw)
The watchdog peripheral on the Raspberry Pi can be used to shutdown by
writing a magic value that the firmware checks for and rebooting.
This is useful to close an emulated Raspberry Pi in QEMU, so add
support.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/watchdog/bcm2835_wdt.c | 21 +++++++++++++++++++++
include/soc/bcm283x/wdt.h | 7 +++++++
2 files changed, 28 insertions(+)
diff --git a/drivers/watchdog/bcm2835_wdt.c b/drivers/watchdog/bcm2835_wdt.c
index 874315d502a9..5b854c49b311 100644
--- a/drivers/watchdog/bcm2835_wdt.c
+++ b/drivers/watchdog/bcm2835_wdt.c
@@ -8,6 +8,7 @@
#include <init.h>
#include <io.h>
#include <restart.h>
+#include <poweroff.h>
#include <watchdog.h>
#include <soc/bcm283x/wdt.h>
@@ -23,6 +24,7 @@ struct bcm2835_wd {
void __iomem *base;
struct device *dev;
struct restart_handler restart;
+ struct poweroff_handler poweroff;
};
#define RESET_TIMEOUT 10
@@ -41,6 +43,20 @@ static void __noreturn bcm2835_restart_soc(struct restart_handler *rst)
hang();
}
+static void __noreturn bcm2835_poweroff_soc(struct poweroff_handler *poweroff)
+{
+ struct bcm2835_wd *priv = container_of(poweroff, struct bcm2835_wd, poweroff);
+ uint32_t val;
+
+ shutdown_barebox();
+
+ val = readl_relaxed(priv->base + PM_RSTS);
+ val |= PM_PASSWORD | PM_RSTS_RASPBERRYPI_HALT;
+ writel_relaxed(val, priv->base + PM_RSTS);
+
+ bcm2835_restart_soc(&priv->restart);
+}
+
static int bcm2835_wd_set_timeout(struct watchdog *wd, unsigned timeout)
{
struct bcm2835_wd *priv = container_of(wd, struct bcm2835_wd, wd);
@@ -86,6 +102,11 @@ static int bcm2835_wd_probe(struct device *dev)
}
}
+ priv->poweroff.name = "bcm2835_wd";
+ priv->poweroff.poweroff = bcm2835_poweroff_soc;
+
+ poweroff_handler_register(&priv->poweroff);
+
priv->restart.name = "bcm2835_wd";
priv->restart.restart = bcm2835_restart_soc;
diff --git a/include/soc/bcm283x/wdt.h b/include/soc/bcm283x/wdt.h
index 2002647b9c39..86e02bcf40f7 100644
--- a/include/soc/bcm283x/wdt.h
+++ b/include/soc/bcm283x/wdt.h
@@ -38,4 +38,11 @@
#define PM_RSTS_HADSR_SET \
(PM_RSTS_HADSRQ_SET | PM_RSTS_HADSRF_SET | PM_RSTS_HADSRH_SET)
+/*
+ * The Raspberry Pi firmware uses the RSTS register to know which partition
+ * to boot from. The partition value is spread into bits 0, 2, 4, 6, 8, 10.
+ * Partition 63 is a special partition used by the firmware to indicate halt.
+ */
+#define PM_RSTS_RASPBERRYPI_HALT 0x555
+
#endif
--
2.39.2
next reply other threads:[~2024-06-11 6:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-11 6:58 Ahmad Fatoum [this message]
2024-06-11 6:58 ` [PATCH 2/2] test: arm: describe Qemu Raspberry Pi 3b labgrid environment Ahmad Fatoum
2024-06-13 7:22 ` [PATCH 1/2] watchdog: bcm2835: add support for powering off SoC 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=20240611065811.2900029-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