From ed666fb12910f46cff73a3869058ea59aef4261b Mon Sep 17 00:00:00 2001 From: Walter Lozano Date: Thu, 23 Jan 2020 16:05:05 -0300 Subject: [PATCH 1/2] watchdog: Use dev_read only if OF_PLATDATA is not enabled Currently watchdog tries to use dev_read_u32_default to get timeout configuration in case OF_CONTROL is enabled. However, if SPL is built with OF_PLATDATA this has no sense as there is no device tree. This patch fixes this issue by only use dev_read_u32_default if OF_CONTROL is enabled but OF_PLATDATA is not. Signed-off-by: Walter Lozano Reviewed-by: Simon Glass --- include/wdt.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/wdt.h b/include/wdt.h index 5bcff24ab3..dd83dfdd32 100644 --- a/include/wdt.h +++ b/include/wdt.h @@ -130,11 +130,10 @@ static inline int initr_watchdog(void) } } - if (CONFIG_IS_ENABLED(OF_CONTROL)) { + if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { timeout = dev_read_u32_default(gd->watchdog_dev, "timeout-sec", WATCHDOG_TIMEOUT_SECS); } - wdt_start(gd->watchdog_dev, timeout * 1000, 0); gd->flags |= GD_FLG_WDT_READY; printf("WDT: Started with%s servicing (%ds timeout)\n", From 6d8eae9ab7d17ca3ce84c5e6e29bd452936ad407 Mon Sep 17 00:00:00 2001 From: Chris Packham Date: Mon, 24 Feb 2020 13:20:33 +1300 Subject: [PATCH 2/2] watchdog: Handle timer wrap around On some platforms/architectures the value from get_timer() can wrap. This is particularly problematic when long-running code needs to measure a time difference as is the case with watchdog_reset() which tries to avoid tickling the watchdog too frequently. Use time_after() from time.h instead of a plain > comparison to avoid any issues with the time wrapping on a system that has been sitting in u-boot for a long time. Signed-off-by: Chris Packham Reviewed-by: Stefan Roese --- drivers/watchdog/wdt-uclass.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c index cf1c527473..d9e4dc7cb8 100644 --- a/drivers/watchdog/wdt-uclass.c +++ b/drivers/watchdog/wdt-uclass.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -83,7 +84,7 @@ void watchdog_reset(void) /* Do not reset the watchdog too often */ now = get_timer(0); - if (now > next_reset) { + if (time_after(now, next_reset)) { next_reset = now + 1000; /* reset every 1000ms */ wdt_reset(gd->watchdog_dev); }