diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2020-10-12 08:26:14 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-10-13 08:45:15 +0200 |
commit | d2748c1ae720ee594fa56d8185b59fbfb222b23b (patch) | |
tree | 2cb74b864e9651b35b99faac214b5998e9277ea6 /arch/sandbox/board/power.c | |
parent | f2b9f45263f839f5e42a9f83ed69af6f39e8b2ae (diff) | |
download | barebox-d2748c1ae720ee594fa56d8185b59fbfb222b23b.tar.gz barebox-d2748c1ae720ee594fa56d8185b59fbfb222b23b.tar.xz |
sandbox: poweroff: migrate to driver probed from device tree
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>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/sandbox/board/power.c')
-rw-r--r-- | arch/sandbox/board/power.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/arch/sandbox/board/power.c b/arch/sandbox/board/power.c new file mode 100644 index 0000000000..ffd8692845 --- /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); |