From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 07/12] sandbox: poweroff: migrate to driver probed from device tree
Date: Mon, 12 Oct 2020 08:26:14 +0200 [thread overview]
Message-ID: <20201012062619.20400-7-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20201012062619.20400-1-a.fatoum@pengutronix.de>
Follow-up will extend the poweroff driver to support system reset source.
Set the stage by renaming the driver to power (as it does reset as well)
and make it probe from device tree, so it can point at the system reset
source syscon via phandle.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2: no changes
---
arch/sandbox/board/Makefile | 2 +-
arch/sandbox/board/power.c | 61 +++++++++++++++++++++++++++++++++++
arch/sandbox/board/poweroff.c | 42 ------------------------
arch/sandbox/dts/sandbox.dts | 4 +++
4 files changed, 66 insertions(+), 43 deletions(-)
create mode 100644 arch/sandbox/board/power.c
delete mode 100644 arch/sandbox/board/poweroff.c
diff --git a/arch/sandbox/board/Makefile b/arch/sandbox/board/Makefile
index 26f6cb192269..e50d2ca0f148 100644
--- a/arch/sandbox/board/Makefile
+++ b/arch/sandbox/board/Makefile
@@ -4,7 +4,7 @@ obj-y += hostfile.o
obj-y += console.o
obj-y += devices.o
obj-y += dtb.o
-obj-y += poweroff.o
+obj-y += power.o
obj-y += dev-random.o
extra-y += barebox.lds
diff --git a/arch/sandbox/board/power.c b/arch/sandbox/board/power.c
new file mode 100644
index 000000000000..ffd8692845ef
--- /dev/null
+++ b/arch/sandbox/board/power.c
@@ -0,0 +1,61 @@
+#include <common.h>
+#include <driver.h>
+#include <poweroff.h>
+#include <restart.h>
+#include <mach/linux.h>
+#include <reset_source.h>
+
+struct sandbox_power {
+ struct restart_handler rst_hang, rst_reexec;
+};
+
+static void sandbox_poweroff(struct poweroff_handler *poweroff)
+{
+ linux_exit();
+}
+
+static void sandbox_rst_hang(struct restart_handler *rst)
+{
+ linux_hang();
+}
+
+static void sandbox_rst_reexec(struct restart_handler *rst)
+{
+ linux_reexec();
+}
+
+static int sandbox_power_probe(struct device_d *dev)
+{
+ struct sandbox_power *power = xzalloc(sizeof(*power));
+
+ poweroff_handler_register_fn(sandbox_poweroff);
+
+ power->rst_hang = (struct restart_handler) {
+ .name = "hang",
+ .restart = sandbox_rst_hang
+ };
+
+ power->rst_reexec = (struct restart_handler) {
+ .name = "reexec", .priority = 200,
+ .restart = sandbox_rst_reexec,
+ };
+
+ restart_handler_register(&power->rst_hang);
+
+ if (IS_ENABLED(CONFIG_SANDBOX_REEXEC))
+ restart_handler_register(&power->rst_reexec);
+
+ return 0;
+}
+
+static __maybe_unused struct of_device_id sandbox_power_dt_ids[] = {
+ { .compatible = "barebox,sandbox-power" },
+ { /* sentinel */ }
+};
+
+static struct driver_d sandbox_power_drv = {
+ .name = "sandbox-power",
+ .of_compatible = sandbox_power_dt_ids,
+ .probe = sandbox_power_probe,
+};
+coredevice_platform_driver(sandbox_power_drv);
diff --git a/arch/sandbox/board/poweroff.c b/arch/sandbox/board/poweroff.c
deleted file mode 100644
index 8ce739af72c1..000000000000
--- a/arch/sandbox/board/poweroff.c
+++ /dev/null
@@ -1,42 +0,0 @@
-#include <common.h>
-#include <init.h>
-#include <poweroff.h>
-#include <restart.h>
-#include <mach/linux.h>
-
-static void sandbox_poweroff(struct poweroff_handler *poweroff)
-{
- linux_exit();
-}
-
-static void sandbox_rst_hang(struct restart_handler *rst)
-{
- linux_hang();
-}
-
-static struct restart_handler rst_hang = {
- .name = "hang",
- .restart = sandbox_rst_hang
-};
-
-static void sandbox_rst_reexec(struct restart_handler *rst)
-{
- linux_reexec();
-}
-
-static struct restart_handler rst_reexec = {
- .name = "reexec", .priority = 200,
- .restart = sandbox_rst_reexec,
-};
-
-static int poweroff_register_feature(void)
-{
- poweroff_handler_register_fn(sandbox_poweroff);
- restart_handler_register(&rst_hang);
-
- if (IS_ENABLED(CONFIG_SANDBOX_REEXEC))
- restart_handler_register(&rst_reexec);
-
- return 0;
-}
-coredevice_initcall(poweroff_register_feature);
diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index afca02d41014..d32999292eb3 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -37,4 +37,8 @@
};
};
};
+
+ power {
+ compatible = "barebox,sandbox-power";
+ };
};
--
2.28.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2020-10-12 6:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-12 6:26 [PATCH v2 01/12] sandbox: dts: retire skeleton.dtsi Ahmad Fatoum
2020-10-12 6:26 ` [PATCH v2 02/12] of: implement of_property_read_u64_array Ahmad Fatoum
2020-10-12 6:26 ` [PATCH v2 03/12] sandbox: hostfile: unify --image and direct device tree probe Ahmad Fatoum
2020-10-12 6:26 ` [PATCH v2 04/12] sandbox: hostfile: support anonymous hostfiles in device tree Ahmad Fatoum
2020-10-12 6:26 ` [PATCH v2 05/12] sandbox: hostfile: maintain created temp files over reset Ahmad Fatoum
2020-10-12 6:26 ` [PATCH v2 06/12] sandbox: dts: define default environment node Ahmad Fatoum
2020-10-12 6:26 ` Ahmad Fatoum [this message]
2020-10-12 6:26 ` [PATCH v2 08/12] sandbox: power: implement reset source support Ahmad Fatoum
2020-10-12 6:26 ` [PATCH v2 09/12] sandbox: dts: implement reboot mode Ahmad Fatoum
2020-10-12 6:26 ` [PATCH v2 10/12] sandbox: add watchdog driver Ahmad Fatoum
2020-10-12 6:26 ` [PATCH v2 11/12] sandbox: dts: include state node by default Ahmad Fatoum
2020-10-12 6:26 ` [PATCH v2 12/12] sandbox: defconfig: enable new generic features Ahmad Fatoum
2020-10-12 14:36 ` [PATCH v2 01/12] sandbox: dts: retire skeleton.dtsi 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=20201012062619.20400-7-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