mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] watchdog: bcm2835: add support for powering off SoC
@ 2024-06-11  6:58 Ahmad Fatoum
  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
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-06-11  6:58 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] test: arm: describe Qemu Raspberry Pi 3b labgrid environment
  2024-06-11  6:58 [PATCH 1/2] watchdog: bcm2835: add support for powering off SoC Ahmad Fatoum
@ 2024-06-11  6:58 ` Ahmad Fatoum
  2024-06-13  7:22 ` [PATCH 1/2] watchdog: bcm2835: add support for powering off SoC Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-06-11  6:58 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The Raspberry Pi 3b has multiple non-secure UARTs, which can be useful
for debugging.

The existing Qemu ARM64 Virt platform can already gain multiple UARTs
via virtio, but PL011/8250 UARTs may be easier to use from secure monitors
or EFI runtime services.

The second console can be connected to with:

  microcom -t localhost:2302

But requires the Bluetooth serdev node to be removed manually for now.

All tests run successfully, but the default heartbeat throws errors,
presumably, because the VideoCore firmware used with Qemu doesn't
implement GPIO control as expected by the gpio-raspberrypi-exp driver
used for heartbeat. This doesn't bother us in CI and can be solved
later on though.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 test/arm/qemu-raspi3b@multi_v8_defconfig.yaml | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 test/arm/qemu-raspi3b@multi_v8_defconfig.yaml

diff --git a/test/arm/qemu-raspi3b@multi_v8_defconfig.yaml b/test/arm/qemu-raspi3b@multi_v8_defconfig.yaml
new file mode 100644
index 000000000000..4f591ba21596
--- /dev/null
+++ b/test/arm/qemu-raspi3b@multi_v8_defconfig.yaml
@@ -0,0 +1,20 @@
+targets:
+  main:
+    drivers:
+      QEMUDriver:
+        qemu_bin: qemu-system-aarch64
+        machine: raspi3b
+        cpu: cortex-a53
+        memory: 1G
+        kernel: barebox-raspberry-pi.img
+        extra_args: "\
+          -serial chardev:serial2 \
+          -chardev socket,id=serial2,host=localhost,port=2302,nodelay=on,server=on,wait=off"
+      BareboxDriver:
+        prompt: 'barebox@[^:]+:[^ ]+ '
+        bootstring: 'commandline:'
+      BareboxTestStrategy: {}
+images:
+  barebox-raspberry-pi.img: !template "$LG_BUILDDIR/images/barebox-raspberry-pi.img"
+imports:
+  -  ../strategy.py
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] watchdog: bcm2835: add support for powering off SoC
  2024-06-11  6:58 [PATCH 1/2] watchdog: bcm2835: add support for powering off SoC Ahmad Fatoum
  2024-06-11  6:58 ` [PATCH 2/2] test: arm: describe Qemu Raspberry Pi 3b labgrid environment Ahmad Fatoum
@ 2024-06-13  7:22 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-06-13  7:22 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Tue, 11 Jun 2024 08:58:10 +0200, Ahmad Fatoum wrote:
> 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.
> 
> 
> [...]

Applied, thanks!

[1/2] watchdog: bcm2835: add support for powering off SoC
      https://git.pengutronix.de/cgit/barebox/commit/?id=ee835e946c91 (link may not be stable)
[2/2] test: arm: describe Qemu Raspberry Pi 3b labgrid environment
      https://git.pengutronix.de/cgit/barebox/commit/?id=ee90dc47d271 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-13  7:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-11  6:58 [PATCH 1/2] watchdog: bcm2835: add support for powering off SoC Ahmad Fatoum
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox