diff options
author | Ahmad Fatoum <ahmad@a3f.at> | 2023-04-24 14:17:59 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2023-05-02 11:33:58 +0200 |
commit | 0dac61dffee68f1dc0173e3b192f197abe02bb20 (patch) | |
tree | ab4861ee2473477f557a3baf06c0f2281cf173dc /arch/sandbox | |
parent | 69435e9707b50de89cd75dfa3d5f777d0d77b3d1 (diff) | |
download | barebox-0dac61dffee68f1dc0173e3b192f197abe02bb20.tar.gz barebox-0dac61dffee68f1dc0173e3b192f197abe02bb20.tar.xz |
sandbox: watchdog: handle missing stickypage gracefully
To enable simulation of $global.system.reset in sandbox, the watchdog
driver writes the reset-source into the stickypage for readout during
subsequent barebox startup. This is an optional feature, so it should
happen before watchdog registration, but not break watchdog operation if
not available.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
Link: https://lore.barebox.org/20230424121805.150434-1-ahmad@a3f.at
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/sandbox')
-rw-r--r-- | arch/sandbox/board/watchdog.c | 28 | ||||
-rw-r--r-- | arch/sandbox/include/asm/reset_source.h | 16 |
2 files changed, 26 insertions, 18 deletions
diff --git a/arch/sandbox/board/watchdog.c b/arch/sandbox/board/watchdog.c index 54e87cdde4..5bffad8119 100644 --- a/arch/sandbox/board/watchdog.c +++ b/arch/sandbox/board/watchdog.c @@ -7,7 +7,7 @@ #include <of.h> #include <watchdog.h> #include <linux/nvmem-consumer.h> -#include <reset_source.h> +#include <asm/reset_source.h> struct sandbox_watchdog { struct watchdog wdd; @@ -30,7 +30,7 @@ static int sandbox_watchdog_set_timeout(struct watchdog *wdd, unsigned int timeo if (timeout > wdd->timeout_max) return -EINVAL; - nvmem_cell_write(wd->reset_source_cell, &(u8) { RESET_WDG }, 1); + sandbox_save_reset_source(wd->reset_source_cell, RESET_WDG); linux_watchdog_set_timeout(timeout); return 0; @@ -41,7 +41,6 @@ static int sandbox_watchdog_probe(struct device *dev) struct device_node *np = dev->of_node; struct sandbox_watchdog *wd; struct watchdog *wdd; - int ret; wd = xzalloc(sizeof(*wd)); @@ -50,24 +49,17 @@ static int sandbox_watchdog_probe(struct device *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; - } - - wd->reset_source_cell = of_nvmem_cell_get(dev->of_node, - "reset-source"); + wd->reset_source_cell = of_nvmem_cell_get(np, "reset-source"); if (IS_ERR(wd->reset_source_cell)) { - dev_warn(dev, "No reset source info available: %pe\n", wd->reset_source_cell); - goto out; + if (PTR_ERR(wd->reset_source_cell) != -EPROBE_DEFER) + dev_warn(dev, "No reset source info available: %pe\n", + wd->reset_source_cell); + wd->reset_source_cell = NULL; } -out: - dev_info(dev, "probed\n"); - return 0; + wd->cant_disable = of_property_read_bool(np, "barebox,cant-disable"); + + return watchdog_register(wdd); } diff --git a/arch/sandbox/include/asm/reset_source.h b/arch/sandbox/include/asm/reset_source.h new file mode 100644 index 0000000000..1690299c47 --- /dev/null +++ b/arch/sandbox/include/asm/reset_source.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __SANDBOX_RESET_SOURCE_H +#define __SANDBOX_RESET_SOURCE_H + +#include <reset_source.h> +#include <linux/nvmem-consumer.h> + +static inline void sandbox_save_reset_source(struct nvmem_cell *reset_source_cell, + enum reset_src_type src) +{ + if (reset_source_cell) + WARN_ON(nvmem_cell_write(reset_source_cell, &(u8) { src }, 1) <= 0); +} + +#endif |