mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/7] sandbox: watchdog: handle missing stickypage gracefully
@ 2023-04-24 12:17 Ahmad Fatoum
  2023-04-24 12:18 ` [PATCH 2/7] sandbox: power: " Ahmad Fatoum
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2023-04-24 12:17 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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>
---
 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

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




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-05-02  9:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-24 12:17 [PATCH 1/7] sandbox: watchdog: handle missing stickypage gracefully Ahmad Fatoum
2023-04-24 12:18 ` [PATCH 2/7] sandbox: power: " Ahmad Fatoum
2023-04-24 12:18 ` [PATCH 3/7] sandbox: hostfile: don't warn on failed hostfile fixup Ahmad Fatoum
2023-04-24 12:18 ` [PATCH 4/7] treewide: drop trailing space Ahmad Fatoum
2023-04-24 12:18 ` [PATCH 5/7] driver: be explicit about supported #feature-cells Ahmad Fatoum
2023-04-24 12:18 ` [PATCH 6/7] featctrl: drop useless NULL check Ahmad Fatoum
2023-04-24 12:18 ` [PATCH 7/7] sandbox: hostfile: add feature controller support Ahmad Fatoum
2023-05-02  9:34 ` [PATCH 1/7] sandbox: watchdog: handle missing stickypage gracefully Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox