On Mon, Apr 24, 2023 at 02:17:59PM +0200, Ahmad Fatoum wrote: > 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@xxxxxx> > --- > arch/sandbox/board/watchdog.c | 28 +++++++++---------------- > arch/sandbox/include/asm/reset_source.h | 16 ++++++++++++++ > 2 files changed, 26 insertions(+), 18 deletions(-) > create mode 100644 arch/sandbox/include/asm/reset_source.h Applied, thanks Sascha > > diff --git a/arch/sandbox/board/watchdog.c b/arch/sandbox/board/watchdog.c > index 54e87cdde4ab..5bffad81195e 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 000000000000..1690299c4718 > --- /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 > -- > 2.38.4 > > > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |