summaryrefslogtreecommitdiffstats
path: root/arch/sandbox/board
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2020-10-12 08:26:17 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-10-13 08:45:15 +0200
commit7bfaaa6ffe72513a1aa8c4bdd73f1324efe32b6b (patch)
treeba0bc39e0f5b82732ce01052c3b779a489571810 /arch/sandbox/board
parent9e0c0930d108ebe2d6c098370417c7694c05dcae (diff)
downloadbarebox-7bfaaa6ffe72513a1aa8c4bdd73f1324efe32b6b.tar.gz
barebox-7bfaaa6ffe72513a1aa8c4bdd73f1324efe32b6b.tar.xz
sandbox: add watchdog driver
Add SIGALRM based watchdog driver. This can reset barebox if stuck and plays nicely with $global.system.reset. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/sandbox/board')
-rw-r--r--arch/sandbox/board/Makefile1
-rw-r--r--arch/sandbox/board/watchdog.c84
2 files changed, 85 insertions, 0 deletions
diff --git a/arch/sandbox/board/Makefile b/arch/sandbox/board/Makefile
index e50d2ca0f1..c504c967de 100644
--- a/arch/sandbox/board/Makefile
+++ b/arch/sandbox/board/Makefile
@@ -6,5 +6,6 @@ obj-y += devices.o
obj-y += dtb.o
obj-y += power.o
obj-y += dev-random.o
+obj-y += watchdog.o
extra-y += barebox.lds
diff --git a/arch/sandbox/board/watchdog.c b/arch/sandbox/board/watchdog.c
new file mode 100644
index 0000000000..336451282f
--- /dev/null
+++ b/arch/sandbox/board/watchdog.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <common.h>
+#include <errno.h>
+#include <driver.h>
+#include <mach/linux.h>
+#include <of.h>
+#include <watchdog.h>
+#include <mfd/syscon.h>
+#include <reset_source.h>
+
+struct sandbox_watchdog {
+ struct watchdog wdd;
+ bool cant_disable :1;
+};
+
+static inline struct sandbox_watchdog *to_sandbox_watchdog(struct watchdog *wdd)
+{
+ return container_of(wdd, struct sandbox_watchdog, wdd);
+}
+
+static int sandbox_watchdog_set_timeout(struct watchdog *wdd, unsigned int timeout)
+{
+ struct sandbox_watchdog *wd = to_sandbox_watchdog(wdd);
+
+ if (!timeout && wd->cant_disable)
+ return -ENOSYS;
+
+ if (timeout > wdd->timeout_max)
+ return -EINVAL;
+
+ return linux_watchdog_set_timeout(timeout);
+}
+
+static int sandbox_watchdog_probe(struct device_d *dev)
+{
+ struct device_node *np = dev->device_node;
+ struct sandbox_watchdog *wd;
+ struct watchdog *wdd;
+ struct regmap *src;
+ u32 src_offset;
+ int ret;
+
+ wd = xzalloc(sizeof(*wd));
+
+ wdd = &wd->wdd;
+ wdd->hwdev = dev;
+ wdd->set_timeout = sandbox_watchdog_set_timeout;
+ wdd->timeout_max = 1000;
+
+ wd->cant_disable = of_property_read_bool(np, "barebox,cant-disable");
+
+ ret = watchdog_register(wdd);
+ if (ret) {
+ dev_err(dev, "Failed to register watchdog device\n");
+ return ret;
+ }
+
+ src = syscon_regmap_lookup_by_phandle(np, "barebox,reset-source");
+ if (IS_ERR(src))
+ return 0;
+
+ ret = of_property_read_u32_index(np, "barebox,reset-source", 1, &src_offset);
+ if (ret)
+ return 0;
+
+ regmap_update_bits(src, src_offset, 0xff, RESET_WDG);
+
+ dev_info(dev, "probed\n");
+ return 0;
+}
+
+
+static __maybe_unused struct of_device_id sandbox_watchdog_dt_ids[] = {
+ { .compatible = "barebox,sandbox-watchdog" },
+ { /* sentinel */ }
+};
+
+static struct driver_d sandbox_watchdog_drv = {
+ .name = "sandbox-watchdog",
+ .of_compatible = sandbox_watchdog_dt_ids,
+ .probe = sandbox_watchdog_probe,
+};
+device_platform_driver(sandbox_watchdog_drv);