mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/7] sandbox: fix probe order dependency between watchdog and power
Date: Mon, 28 Jun 2021 08:45:12 +0200	[thread overview]
Message-ID: <20210628064517.28636-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210628064517.28636-1-a.fatoum@pengutronix.de>

With incoming changes to enable deep probe for sandbox, watchdog driver
may be probed before power driver, which so far didn't happen. Because
the watchdog driver writes the same NVMEM cell read by the power driver,
the original value of the nvmem cell (used for $global.system.reset)
will be lost. Work around this by writing the WDG reset reason only
at first watchdog enable which is guaranteed to happen after power
driver probe. We don't need to reset the nvmem cell on watchdog disable,
because all other reset methods will already overwrite the cell with
the correct value.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/sandbox/board/watchdog.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/arch/sandbox/board/watchdog.c b/arch/sandbox/board/watchdog.c
index ff26a2019fac..daaf549642e3 100644
--- a/arch/sandbox/board/watchdog.c
+++ b/arch/sandbox/board/watchdog.c
@@ -12,6 +12,7 @@
 struct sandbox_watchdog {
 	struct watchdog wdd;
 	bool cant_disable :1;
+	struct nvmem_cell *reset_source_cell;
 };
 
 static inline struct sandbox_watchdog *to_sandbox_watchdog(struct watchdog *wdd)
@@ -29,6 +30,8 @@ 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);
+
 	linux_watchdog_set_timeout(timeout);
 	return 0;
 }
@@ -36,7 +39,6 @@ static int sandbox_watchdog_set_timeout(struct watchdog *wdd, unsigned int timeo
 static int sandbox_watchdog_probe(struct device_d *dev)
 {
 	struct device_node *np = dev->device_node;
-	struct nvmem_cell *reset_source_cell;
 	struct sandbox_watchdog *wd;
 	struct watchdog *wdd;
 	int ret;
@@ -56,16 +58,12 @@ static int sandbox_watchdog_probe(struct device_d *dev)
 		return ret;
 	}
 
-	reset_source_cell = of_nvmem_cell_get(dev->device_node, "reset-source");
-	if (IS_ERR(reset_source_cell)) {
-		dev_warn(dev, "No reset source info available: %pe\n", reset_source_cell);
+	wd->reset_source_cell = of_nvmem_cell_get(dev->device_node, "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;
 	}
 
-	nvmem_cell_write(reset_source_cell, &(u8) { RESET_WDG }, 1);
-
-	nvmem_cell_put(reset_source_cell);
-
 out:
 	dev_info(dev, "probed\n");
 	return 0;
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2021-06-28  6:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28  6:45 [PATCH 0/7] sandbox: turn into deep probe platform Ahmad Fatoum
2021-06-28  6:45 ` [PATCH 1/7] sandbox: power: set $global.system.reset=POR on poweroff Ahmad Fatoum
2021-06-28  6:45 ` Ahmad Fatoum [this message]
2021-06-28  6:45 ` [PATCH 3/7] of: partition: implement of_partition_ensure_probed Ahmad Fatoum
2021-06-28  6:45 ` [PATCH 4/7] state: support deep probe Ahmad Fatoum
2021-06-28  6:45 ` [PATCH 5/7] nvmem: " Ahmad Fatoum
2021-06-28  6:45 ` [PATCH 6/7] sandbox: turn into deep probe platform Ahmad Fatoum
2021-06-28  6:45 ` [PATCH 7/7] Revert "sandbox: hostfile: move initcall to earlier postcore level" Ahmad Fatoum
2021-07-18  5:14 ` [PATCH 0/7] sandbox: turn into deep probe platform Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210628064517.28636-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox