summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2022-01-19 09:26:42 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2022-01-19 09:26:42 +0100
commit5c3c23f10ac4a478e2f2ab3ff689422c19268022 (patch)
tree63f5c3ebd90fceda6d3574a57497a1941d8d0a0e /drivers
parentbe1539b920302cfcde300f8e8607d548e1f75b8a (diff)
parent0d1fc926e8ad71d4f4626d58b3b447c1856d3703 (diff)
downloadbarebox-5c3c23f10ac4a478e2f2ab3ff689422c19268022.tar.gz
barebox-5c3c23f10ac4a478e2f2ab3ff689422c19268022.tar.xz
Merge branch 'for-next/riscv'
Diffstat (limited to 'drivers')
-rw-r--r--drivers/power/reset/Kconfig7
-rw-r--r--drivers/power/reset/Makefile1
-rw-r--r--drivers/power/reset/htif-poweroff.c46
3 files changed, 54 insertions, 0 deletions
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index e4151d8bc6..968d4b8ba4 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -54,3 +54,10 @@ config POWER_RESET_GPIO_RESTART
This driver supports restarting your board via a GPIO line.
If your board needs a GPIO high/low to restart, say Y and
create a binding in your devicetree.
+
+config POWER_RESET_HTIF_POWEROFF
+ bool "HTIF poweroff driver"
+ depends on RISCV
+ help
+ Adds poweroff support via the syscall device on systems
+ supporting the UC Berkely Host/Target Interface (HTIF).
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index 10d6f2a41e..c581382be8 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_POWER_RESET_SYSCON) += syscon-reboot.o
obj-$(CONFIG_POWER_RESET_SYSCON_POWEROFF) += syscon-poweroff.o
obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o
+obj-$(CONFIG_POWER_RESET_HTIF_POWEROFF) += htif-poweroff.o
diff --git a/drivers/power/reset/htif-poweroff.c b/drivers/power/reset/htif-poweroff.c
new file mode 100644
index 0000000000..8df060d507
--- /dev/null
+++ b/drivers/power/reset/htif-poweroff.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021 Ahmad Fatoum, Pengutronix
+ */
+
+#include <common.h>
+#include <driver.h>
+#include <poweroff.h>
+#include <asm/htif.h>
+
+static void __iomem *htif = IOMEM(HTIF_DEFAULT_BASE_ADDR);
+
+static void __noreturn riscvemu_poweroff(struct poweroff_handler *pwr)
+{
+ shutdown_barebox();
+
+ __htif_tohost(htif, HTIF_DEV_SYSCALL, 0, 1);
+
+ __builtin_unreachable();
+}
+
+static int htif_poweroff_probe(struct device_d *dev)
+{
+ struct resource *iores;
+
+ iores = dev_request_mem_resource(dev, 0);
+ if (!IS_ERR(iores))
+ htif = IOMEM(iores->start);
+ else if (PTR_ERR(iores) != -ENOENT)
+ return PTR_ERR(iores);
+
+ return poweroff_handler_register_fn(riscvemu_poweroff);
+}
+
+
+static const struct of_device_id htif_poweroff_of_match[] = {
+ { .compatible = "ucb,htif0" },
+ {}
+};
+
+static struct driver_d htif_poweroff_driver = {
+ .name = "htif-poweroff",
+ .of_compatible = htif_poweroff_of_match,
+ .probe = htif_poweroff_probe,
+};
+coredevice_platform_driver(htif_poweroff_driver);