Skip to contentSkip to conversation

watchdog: Set/unset GD_FLG_WDT_READY flag in wdt_start()/wdt_stop()

PATCH Superseded Pali Rohár 2 participants 20 messages Mar 5, 2021 – Apr 6, 2021 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 watchdog: Set/unset GD_FLG_WDT_READY flag in wdt_start()/wdt_stop()

Watchdog is ready after successful call of ops->start() callback in wdt_start() function. And is stopped after successful call of ops->stop() callback in wdt_stop function.

So move setting of GD_FLG_WDT_READY flag from initr_watchdog() function to wdt_start() and ensure that GD_FLG_WDT_READY flag is unset in wdt_stop() function.

This change ensures that GD_FLG_WDT_READY flag is set only when watchdog is running. And ensures that flag is also also when watchdog was started not only by initr_watchdog() call (e.g. by U-Boot 'wdt' command).

---
 drivers/watchdog/wdt-uclass.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/watchdog/wdt-uclass.c +12 -3
index 28f7918c4673..3f707f61f74f 100644
@@ -51,7 +51,6 @@ int initr_watchdog(void)
 	}
 
 	wdt_start(gd->watchdog_dev, timeout * 1000, 0);
-	gd->flags |= GD_FLG_WDT_READY;
 	printf("WDT:   Started with%s servicing (%ds timeout)\n",
 	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
 
@@ -61,21 +60,31 @@ int initr_watchdog(void)
 int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
 {
 	const struct wdt_ops *ops = device_get_ops(dev);
+	int ret;
 
 	if (!ops->start)
 		return -ENOSYS;
 
-	return ops->start(dev, timeout_ms, flags);
+	ret = ops->start(dev, timeout_ms, flags);
+	if (ret == 0)
+		gd->flags |= GD_FLG_WDT_READY;
+
+	return ret;
 }
 
 int wdt_stop(struct udevice *dev)
 {
 	const struct wdt_ops *ops = device_get_ops(dev);
+	int ret;
 
 	if (!ops->stop)
 		return -ENOSYS;
 
-	return ops->stop(dev);
+	ret = ops->stop(dev);
+	if (ret == 0)
+		gd->flags &= ~GD_FLG_WDT_READY;
+
+	return ret;
 }
 
 int wdt_reset(struct udevice *dev)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/4 watchdog: Show error message when initr_watchdog() cannot start watchdog

Function wdt_start() may fail. So in initr_watchdog() function check return value of wdt_start() call and print error message when watchdog starting failed.

---
 drivers/watchdog/wdt-uclass.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/watchdog/wdt-uclass.c +7 -1
index 3f707f61f74f..7500b3ed90e3 100644
@@ -27,6 +27,7 @@ static ulong reset_period = 1000;
 int initr_watchdog(void)
 {
 	u32 timeout = WATCHDOG_TIMEOUT_SECS;
+	int ret;
 
 	/*
 	 * Init watchdog: This will call the probe function of the
@@ -50,7 +51,12 @@ int initr_watchdog(void)
 						    4 * reset_period) / 4;
 	}
 
-	wdt_start(gd->watchdog_dev, timeout * 1000, 0);
+	ret = wdt_start(gd->watchdog_dev, timeout * 1000, 0);
+	if (ret != 0) {
+		printf("WDT:   Failed to start\n");
+		return 0;
+	}
+
 	printf("WDT:   Started with%s servicing (%ds timeout)\n",
 	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
 
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/4 watchdog: Allow to use CONFIG_WDT without starting watchdog

In reply to Pali Rohár

In some cases it is useful to compile support for U-Boot command 'wdt' without starting HW watchdog in early U-Boot phase. For example when user want to start watchdog only on demand by some boot script.

This change adds a new compile option WATCHDOG_AUTOSTART to control whether U-Boot should automatically start watchdog during init phase or not.

This option is enabled by default as it was was default behavior prior introducing this new change. When compiling U-Boot users can decide to turn this option off.

---
 drivers/watchdog/Kconfig      | 13 +++++++++++++
 drivers/watchdog/wdt-uclass.c |  7 +++++++
 2 files changed, 20 insertions(+)
drivers/watchdog/Kconfig +13 -0
index 602ccbe41c00..aa76a8f2d239 100644
@@ -9,6 +9,19 @@ config WATCHDOG
 	  this option if you want to service enabled watchdog by U-Boot. Disable
 	  this option if you want U-Boot to start watchdog but never service it.
 
+config WATCHDOG_AUTOSTART
+	bool "Automatically start watchdog timer"
+	depends on WDT
+	default y
+	help
+	  Automatically start watchdog timer and start servicing it during
+	  init phase. Enabled by default. Disable this option if you want
+	  to compile U-Boot with CONFIG_WDT support but do not want to
+	  activate watchdog, like when CONFIG_WDT option is disabled. You
+	  would be able to start watchdog manually by 'wdt' command. Useful
+	  when you want to have support for 'wdt' command but do not want
+	  to have watchdog enabled by default.
+
 config WATCHDOG_TIMEOUT_MSECS
 	int "Watchdog timeout in msec"
 	default 128000 if ARCH_MX25 || ARCH_MX31 || ARCH_MX5 || ARCH_MX6
drivers/watchdog/wdt-uclass.c +7 -0
index 7500b3ed90e3..00a408bf5cc5 100644
@@ -27,7 +27,9 @@ static ulong reset_period = 1000;
 int initr_watchdog(void)
 {
 	u32 timeout = WATCHDOG_TIMEOUT_SECS;
+#ifdef CONFIG_WATCHDOG_AUTOSTART
 	int ret;
+#endif
 
 	/*
 	 * Init watchdog: This will call the probe function of the
@@ -51,6 +53,10 @@ int initr_watchdog(void)
 						    4 * reset_period) / 4;
 	}
 
+#ifndef CONFIG_WATCHDOG_AUTOSTART
+	printf("WDT:   Not starting\n");
+	return 0;
+#else
 	ret = wdt_start(gd->watchdog_dev, timeout * 1000, 0);
 	if (ret != 0) {
 		printf("WDT:   Failed to start\n");
@@ -61,6 +67,7 @@ int initr_watchdog(void)
 	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
 
 	return 0;
+#endif
 }
 
 int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
Signature · 1 line
2.20.1
#8 lore raw

PATCH 4/4 arm: mvebu: Espressobin: Enable watchdog support but do not start it

In reply to Pali Rohár

Espressobin had disabled watchdog support (CONFIG_WDT) because older stable Linux kernel versions (which are used by current stable OpenWRT and Debian versions) do not have support for Armada 3700 watchdog driver. Therefore they are not able to periodically kick watchdog so Espressobin enter into boot loop.

This change enable CONFIG_WDT, CONFIG_WDT_ARMADA_37XX and CONFIG_CMD_WDT options which add support for U-Boot 'wdt' command. And unset new CONFIG_WATCHDOG_AUTOSTART option which cause that watchdog is not automatically started by U-Boot during init phase, like when CONFIG_WDT option is not set at all.

So with this change, U-Boot on Espressobin would have working 'wdt' command which can be used from boot scripts (e.g. for enabling watchdog prior new Linux booting kernel). But default behavior of watchdog status stays unchanged, U-Boot does not start watchdog on Espressobin during its init phase.

---
 configs/mvebu_espressobin-88f3720_defconfig | 4 ++++
 1 file changed, 4 insertions(+)
configs/mvebu_espressobin-88f3720_defconfig +4 -0
index c791f98dfea5..20aa21b06b3d 100644
@@ -32,6 +32,7 @@ CONFIG_CMD_MMC=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_SPI=y
 CONFIG_CMD_USB=y
+CONFIG_CMD_WDT=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_TIME=y
@@ -88,5 +89,8 @@ CONFIG_USB_ETHER_ASIX=y
 CONFIG_USB_ETHER_MCS7830=y
 CONFIG_USB_ETHER_RTL8152=y
 CONFIG_USB_ETHER_SMSC95XX=y
+# CONFIG_WATCHDOG_AUTOSTART is not set
+CONFIG_WDT=y
+CONFIG_WDT_ARMADA_37XX=y
 CONFIG_SHA1=y
 CONFIG_SHA256=y
Signature · 1 line
2.20.1
#10 lore raw

PATCH 1/4 watchdog: Set/unset GD_FLG_WDT_READY flag in wdt_start()/wdt_stop()

In reply to Pali Rohár
Quoted 8 lines · Pali Roh?r

Watchdog is ready after successful call of ops->start() callback in wdt_start() function. And is stopped after successful call of ops->stop() callback in wdt_stop function.

So move setting of GD_FLG_WDT_READY flag from initr_watchdog() function to wdt_start() and ensure that GD_FLG_WDT_READY flag is unset in wdt_stop() function.

Quoted 5 lines

This change ensures that GD_FLG_WDT_READY flag is set only when watchdog is running. And ensures that flag is also also when watchdog was started not only by initr_watchdog() call (e.g. by U-Boot 'wdt' command).

Thanks,
Stefan

Quoted 41 lines
---
  drivers/watchdog/wdt-uclass.c | 15 ++++++++++++---
  1 file changed, 12 insertions(+), 3 deletions(-)
drivers/watchdog/wdt-uclass.c +7 -2
index 28f7918c4673..3f707f61f74f 100644
@@ -51,7 +51,6 @@ int initr_watchdog(void)
  	}
 
  	wdt_start(gd->watchdog_dev, timeout * 1000, 0);
-	gd->flags |= GD_FLG_WDT_READY;
  	printf("WDT:   Started with%s servicing (%ds timeout)\n",
  	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
 
@@ -61,21 +60,31 @@ int initr_watchdog(void)
  int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
  {
  	const struct wdt_ops *ops = device_get_ops(dev);
+	int ret;
 
  	if (!ops->start)
  		return -ENOSYS;
 
-	return ops->start(dev, timeout_ms, flags);
+	ret = ops->start(dev, timeout_ms, flags);
+	if (ret == 0)
+		gd->flags |= GD_FLG_WDT_READY;
+
+	return ret;
  }
 
  int wdt_stop(struct udevice *dev)
  {
  	const struct wdt_ops *ops = device_get_ops(dev);
+	int ret;
 
  	if (!ops->stop)
  		return -ENOSYS;

drivers/watchdog/wdt-uclass.c int initr_watchdog(void) · line 90

Quoted 10 lines
drivers/watchdog/wdt-uclass.c +5 -1
 
-	return ops->stop(dev);
+	ret = ops->stop(dev);
+	if (ret == 0)
+		gd->flags &= ~GD_FLG_WDT_READY;
+
+	return ret;
  }
 
  int wdt_reset(struct udevice *dev)

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
#2 lore raw

PATCH 2/4 watchdog: Show error message when initr_watchdog() cannot start watchdog

In reply to Pali Rohár
Quoted 5 lines · Pali Roh?r

Function wdt_start() may fail. So in initr_watchdog() function check return value of wdt_start() call and print error message when watchdog starting failed.

Thanks,
Stefan

Quoted 21 lines
---
  drivers/watchdog/wdt-uclass.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/watchdog/wdt-uclass.c +1 -0
index 3f707f61f74f..7500b3ed90e3 100644
@@ -27,6 +27,7 @@ static ulong reset_period = 1000;
  int initr_watchdog(void)
  {
  	u32 timeout = WATCHDOG_TIMEOUT_SECS;
+	int ret;
 
  	/*
  	 * Init watchdog: This will call the probe function of the
@@ -50,7 +51,12 @@ int initr_watchdog(void)
  						    4 * reset_period) / 4;
  	}
 

drivers/watchdog/wdt-uclass.c int initr_watchdog(void) · line 62

Quoted 10 lines
drivers/watchdog/wdt-uclass.c +6 -1
-	wdt_start(gd->watchdog_dev, timeout * 1000, 0);
+	ret = wdt_start(gd->watchdog_dev, timeout * 1000, 0);
+	if (ret != 0) {
+		printf("WDT:   Failed to start\n");
+		return 0;
+	}
+
  	printf("WDT:   Started with%s servicing (%ds timeout)\n",
  	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
 

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
#4 lore raw

PATCH 3/4 watchdog: Allow to use CONFIG_WDT without starting watchdog

In reply to Pali Rohár
Quoted 2 lines · Pali Roh?r

In some cases it is useful to compile support for U-Boot command 'wdt' without starting HW watchdog in early U-Boot phase. For example when user

Nitpicking:
when "the" user

Quoted 4 lines

want to start watchdog only on demand by some boot script.

This change adds a new compile option WATCHDOG_AUTOSTART to control whether U-Boot should automatically start watchdog during init phase or not.

start "the" watchdog

Quoted 2 lines

This option is enabled by default as it was was default behavior prior

as it was the default

Quoted 38 lines

introducing this new change. When compiling U-Boot users can decide to turn this option off.

---
  drivers/watchdog/Kconfig      | 13 +++++++++++++
  drivers/watchdog/wdt-uclass.c |  7 +++++++
  2 files changed, 20 insertions(+)
drivers/watchdog/Kconfig +13 -0
index 602ccbe41c00..aa76a8f2d239 100644
@@ -9,6 +9,19 @@ config WATCHDOG
  	  this option if you want to service enabled watchdog by U-Boot. Disable
  	  this option if you want U-Boot to start watchdog but never service it.
 
+config WATCHDOG_AUTOSTART
+	bool "Automatically start watchdog timer"
+	depends on WDT
+	default y
+	help
+	  Automatically start watchdog timer and start servicing it during
+	  init phase. Enabled by default. Disable this option if you want
+	  to compile U-Boot with CONFIG_WDT support but do not want to
+	  activate watchdog, like when CONFIG_WDT option is disabled. You
+	  would be able to start watchdog manually by 'wdt' command. Useful
+	  when you want to have support for 'wdt' command but do not want
+	  to have watchdog enabled by default.
+
  config WATCHDOG_TIMEOUT_MSECS
  	int "Watchdog timeout in msec"
  	default 128000 if ARCH_MX25 || ARCH_MX31 || ARCH_MX5 || ARCH_MX6
drivers/watchdog/wdt-uclass.c +0 -0
index 7500b3ed90e3..00a408bf5cc5 100644

drivers/watchdog/wdt-uclass.c static ulong reset_period = 1000; · line 32

Quoted 6 lines
drivers/watchdog/wdt-uclass.c +2 -0
@@ -27,7 +27,9 @@ static ulong reset_period = 1000;
  int initr_watchdog(void)
  {
  	u32 timeout = WATCHDOG_TIMEOUT_SECS;
+#ifdef CONFIG_WATCHDOG_AUTOSTART
  	int ret;
+#endif

Please don't add more #ifdef's if possible, see below...

Quoted 15 lines
drivers/watchdog/wdt-uclass.c +4 -0
  	/*
  	 * Init watchdog: This will call the probe function of the
@@ -51,6 +53,10 @@ int initr_watchdog(void)
  						    4 * reset_period) / 4;
  	}
 
+#ifndef CONFIG_WATCHDOG_AUTOSTART
+	printf("WDT:   Not starting\n");
+	return 0;
+#else
  	ret = wdt_start(gd->watchdog_dev, timeout * 1000, 0);
  	if (ret != 0) {
  		printf("WDT:   Failed to start\n");

drivers/watchdog/wdt-uclass.c int initr_watchdog(void) · line 70

Quoted 4 lines
drivers/watchdog/wdt-uclass.c +1 -0
@@ -61,6 +67,7 @@ int initr_watchdog(void)
  	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
 
  	return 0;
+#endif

Please use this instead here:

	if (CONFIG_IS_ENABLED(WATCHDOG_AUTOSTART)) {
	...

Thanks,
Stefan

drivers/watchdog/wdt-uclass.c int initr_watchdog(void) · line 73

Quoted 4 lines
drivers/watchdog/wdt-uclass.c +0 -0
  }
 
  int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
#9 lore raw

PATCH 4/4 arm: mvebu: Espressobin: Enable watchdog support but do not start it

In reply to Pali Rohár
Quoted 12 lines · Pali Roh?r

Espressobin had disabled watchdog support (CONFIG_WDT) because older stable Linux kernel versions (which are used by current stable OpenWRT and Debian versions) do not have support for Armada 3700 watchdog driver. Therefore they are not able to periodically kick watchdog so Espressobin enter into boot loop.

This change enable CONFIG_WDT, CONFIG_WDT_ARMADA_37XX and CONFIG_CMD_WDT options which add support for U-Boot 'wdt' command. And unset new CONFIG_WATCHDOG_AUTOSTART option which cause that watchdog is not automatically started by U-Boot during init phase, like when CONFIG_WDT option is not set at all.

Quoted 7 lines

So with this change, U-Boot on Espressobin would have working 'wdt' command which can be used from boot scripts (e.g. for enabling watchdog prior new Linux booting kernel). But default behavior of watchdog status stays unchanged, U-Boot does not start watchdog on Espressobin during its init phase.

Thanks,
Stefan

Quoted 18 lines
---
  configs/mvebu_espressobin-88f3720_defconfig | 4 ++++
  1 file changed, 4 insertions(+)
configs/mvebu_espressobin-88f3720_defconfig +1 -0
index c791f98dfea5..20aa21b06b3d 100644
@@ -32,6 +32,7 @@ CONFIG_CMD_MMC=y
  CONFIG_CMD_PCI=y
  CONFIG_CMD_SPI=y
  CONFIG_CMD_USB=y
+CONFIG_CMD_WDT=y
  CONFIG_CMD_TFTPPUT=y
  CONFIG_CMD_CACHE=y
  CONFIG_CMD_TIME=y

configs/mvebu_espressobin-88f3720_defconfig CONFIG_USB_ETHER_ASIX=y · line 96

Quoted 8 lines
configs/mvebu_espressobin-88f3720_defconfig +3 -0
@@ -88,5 +89,8 @@ CONFIG_USB_ETHER_ASIX=y
  CONFIG_USB_ETHER_MCS7830=y
  CONFIG_USB_ETHER_RTL8152=y
  CONFIG_USB_ETHER_SMSC95XX=y
+# CONFIG_WATCHDOG_AUTOSTART is not set
+CONFIG_WDT=y
+CONFIG_WDT_ARMADA_37XX=y
  CONFIG_SHA1=y
  CONFIG_SHA256=y

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
#11 lore raw

PATCH v2 1/4 watchdog: Set/unset GD_FLG_WDT_READY flag in wdt_start()/wdt_stop()

In reply to Pali Rohár

Watchdog is ready after successful call of ops->start() callback in wdt_start() function. And is stopped after successful call of ops->stop() callback in wdt_stop function.

So move setting of GD_FLG_WDT_READY flag from initr_watchdog() function to wdt_start() and ensure that GD_FLG_WDT_READY flag is unset in wdt_stop() function.

This change ensures that GD_FLG_WDT_READY flag is set only when watchdog is running. And ensures that flag is also also when watchdog was started not only by initr_watchdog() call (e.g. by U-Boot 'wdt' command).

---
 drivers/watchdog/wdt-uclass.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/watchdog/wdt-uclass.c +12 -3
index 28f7918c4673..3f707f61f74f 100644
@@ -51,7 +51,6 @@ int initr_watchdog(void)
 	}
 
 	wdt_start(gd->watchdog_dev, timeout * 1000, 0);
-	gd->flags |= GD_FLG_WDT_READY;
 	printf("WDT:   Started with%s servicing (%ds timeout)\n",
 	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
 
@@ -61,21 +60,31 @@ int initr_watchdog(void)
 int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
 {
 	const struct wdt_ops *ops = device_get_ops(dev);
+	int ret;
 
 	if (!ops->start)
 		return -ENOSYS;
 
-	return ops->start(dev, timeout_ms, flags);
+	ret = ops->start(dev, timeout_ms, flags);
+	if (ret == 0)
+		gd->flags |= GD_FLG_WDT_READY;
+
+	return ret;
 }
 
 int wdt_stop(struct udevice *dev)
 {
 	const struct wdt_ops *ops = device_get_ops(dev);
+	int ret;
 
 	if (!ops->stop)
 		return -ENOSYS;
 
-	return ops->stop(dev);
+	ret = ops->stop(dev);
+	if (ret == 0)
+		gd->flags &= ~GD_FLG_WDT_READY;
+
+	return ret;
 }
 
 int wdt_reset(struct udevice *dev)
Signature · 1 line
2.20.1
#12 lore raw

PATCH v2 2/4 watchdog: Show error message when initr_watchdog() cannot start watchdog

Function wdt_start() may fail. So in initr_watchdog() function check return value of wdt_start() call and print error message when watchdog starting failed.

---
 drivers/watchdog/wdt-uclass.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/watchdog/wdt-uclass.c +7 -1
index 3f707f61f74f..7500b3ed90e3 100644
@@ -27,6 +27,7 @@ static ulong reset_period = 1000;
 int initr_watchdog(void)
 {
 	u32 timeout = WATCHDOG_TIMEOUT_SECS;
+	int ret;
 
 	/*
 	 * Init watchdog: This will call the probe function of the
@@ -50,7 +51,12 @@ int initr_watchdog(void)
 						    4 * reset_period) / 4;
 	}
 
-	wdt_start(gd->watchdog_dev, timeout * 1000, 0);
+	ret = wdt_start(gd->watchdog_dev, timeout * 1000, 0);
+	if (ret != 0) {
+		printf("WDT:   Failed to start\n");
+		return 0;
+	}
+
 	printf("WDT:   Started with%s servicing (%ds timeout)\n",
 	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
 
Signature · 1 line
2.20.1
#14 lore raw

PATCH v2 3/4 watchdog: Allow to use CONFIG_WDT without starting watchdog

In reply to Pali Rohár

In some cases it is useful to compile support for U-Boot command 'wdt' without starting HW watchdog in early U-Boot phase. For example when the user want to start the watchdog only on demand by some boot script.

This change adds a new compile option WATCHDOG_AUTOSTART to control whether U-Boot should automatically start the watchdog during init phase or not.

This option is enabled by default as it was the default behavior prior introducing this new change. When compiling U-Boot users can decide to turn this option off.

---
 drivers/watchdog/Kconfig      | 13 +++++++++++++
 drivers/watchdog/wdt-uclass.c |  5 +++++
 2 files changed, 18 insertions(+)
drivers/watchdog/Kconfig +13 -0
index 602ccbe41c00..aa76a8f2d239 100644
@@ -9,6 +9,19 @@ config WATCHDOG
 	  this option if you want to service enabled watchdog by U-Boot. Disable
 	  this option if you want U-Boot to start watchdog but never service it.
 
+config WATCHDOG_AUTOSTART
+	bool "Automatically start watchdog timer"
+	depends on WDT
+	default y
+	help
+	  Automatically start watchdog timer and start servicing it during
+	  init phase. Enabled by default. Disable this option if you want
+	  to compile U-Boot with CONFIG_WDT support but do not want to
+	  activate watchdog, like when CONFIG_WDT option is disabled. You
+	  would be able to start watchdog manually by 'wdt' command. Useful
+	  when you want to have support for 'wdt' command but do not want
+	  to have watchdog enabled by default.
+
 config WATCHDOG_TIMEOUT_MSECS
 	int "Watchdog timeout in msec"
 	default 128000 if ARCH_MX25 || ARCH_MX31 || ARCH_MX5 || ARCH_MX6
drivers/watchdog/wdt-uclass.c +5 -0
index 7500b3ed90e3..0603ffbd36d9 100644
@@ -51,6 +51,11 @@ int initr_watchdog(void)
 						    4 * reset_period) / 4;
 	}
 
+	if (!CONFIG_IS_ENABLED(WATCHDOG_AUTOSTART)) {
+		printf("WDT:   Not starting\n");
+		return 0;
+	}
+
 	ret = wdt_start(gd->watchdog_dev, timeout * 1000, 0);
 	if (ret != 0) {
 		printf("WDT:   Failed to start\n");
Signature · 1 line
2.20.1
#16 lore raw

PATCH v2 4/4 arm: mvebu: Espressobin: Enable watchdog support but do not start it

In reply to Pali Rohár

Espressobin had disabled watchdog support (CONFIG_WDT) because older stable Linux kernel versions (which are used by current stable OpenWRT and Debian versions) do not have support for Armada 3700 watchdog driver. Therefore they are not able to periodically kick watchdog so Espressobin enter into boot loop.

This change enable CONFIG_WDT, CONFIG_WDT_ARMADA_37XX and CONFIG_CMD_WDT options which add support for U-Boot 'wdt' command. And unset new CONFIG_WATCHDOG_AUTOSTART option which cause that watchdog is not automatically started by U-Boot during init phase, like when CONFIG_WDT option is not set at all.

So with this change, U-Boot on Espressobin would have working 'wdt' command which can be used from boot scripts (e.g. for enabling watchdog prior new Linux booting kernel). But default behavior of watchdog status stays unchanged, U-Boot does not start watchdog on Espressobin during its init phase.

---
 configs/mvebu_espressobin-88f3720_defconfig | 4 ++++
 1 file changed, 4 insertions(+)
configs/mvebu_espressobin-88f3720_defconfig +4 -0
index c791f98dfea5..20aa21b06b3d 100644
@@ -32,6 +32,7 @@ CONFIG_CMD_MMC=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_SPI=y
 CONFIG_CMD_USB=y
+CONFIG_CMD_WDT=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_TIME=y
@@ -88,5 +89,8 @@ CONFIG_USB_ETHER_ASIX=y
 CONFIG_USB_ETHER_MCS7830=y
 CONFIG_USB_ETHER_RTL8152=y
 CONFIG_USB_ETHER_SMSC95XX=y
+# CONFIG_WATCHDOG_AUTOSTART is not set
+CONFIG_WDT=y
+CONFIG_WDT_ARMADA_37XX=y
 CONFIG_SHA1=y
 CONFIG_SHA256=y
Signature · 1 line
2.20.1
#5 lore raw

PATCH 3/4 watchdog: Allow to use CONFIG_WDT without starting watchdog

In reply to Stefan Roese
Quoted 90 lines · On Tuesday 09 March 2021 12:33:24 Stefan Roese wrote:
Quoted 2 lines · Pali Roh?r

In some cases it is useful to compile support for U-Boot command 'wdt' without starting HW watchdog in early U-Boot phase. For example when user

Nitpicking:
when "the" user

Quoted 4 lines

want to start watchdog only on demand by some boot script.

This change adds a new compile option WATCHDOG_AUTOSTART to control whether U-Boot should automatically start watchdog during init phase or not.

start "the" watchdog

Quoted 2 lines

This option is enabled by default as it was was default behavior prior

as it was the default

Quoted 37 lines

introducing this new change. When compiling U-Boot users can decide to turn this option off.

---
  drivers/watchdog/Kconfig      | 13 +++++++++++++
  drivers/watchdog/wdt-uclass.c |  7 +++++++
  2 files changed, 20 insertions(+)
drivers/watchdog/Kconfig +13 -0
index 602ccbe41c00..aa76a8f2d239 100644
@@ -9,6 +9,19 @@ config WATCHDOG
  	  this option if you want to service enabled watchdog by U-Boot. Disable
  	  this option if you want U-Boot to start watchdog but never service it.
+config WATCHDOG_AUTOSTART
+	bool "Automatically start watchdog timer"
+	depends on WDT
+	default y
+	help
+	  Automatically start watchdog timer and start servicing it during
+	  init phase. Enabled by default. Disable this option if you want
+	  to compile U-Boot with CONFIG_WDT support but do not want to
+	  activate watchdog, like when CONFIG_WDT option is disabled. You
+	  would be able to start watchdog manually by 'wdt' command. Useful
+	  when you want to have support for 'wdt' command but do not want
+	  to have watchdog enabled by default.
+
  config WATCHDOG_TIMEOUT_MSECS
  	int "Watchdog timeout in msec"
  	default 128000 if ARCH_MX25 || ARCH_MX31 || ARCH_MX5 || ARCH_MX6
drivers/watchdog/wdt-uclass.c +0 -0
index 7500b3ed90e3..00a408bf5cc5 100644

drivers/watchdog/wdt-uclass.c static ulong reset_period = 1000; · line 32

Quoted 6 lines
drivers/watchdog/wdt-uclass.c +2 -0
@@ -27,7 +27,9 @@ static ulong reset_period = 1000;
  int initr_watchdog(void)
  {
  	u32 timeout = WATCHDOG_TIMEOUT_SECS;
+#ifdef CONFIG_WATCHDOG_AUTOSTART
  	int ret;
+#endif

Please don't add more #ifdef's if possible, see below...

Quoted 13 lines
drivers/watchdog/wdt-uclass.c +4 -0
  	/*
  	 * Init watchdog: This will call the probe function of the
@@ -51,6 +53,10 @@ int initr_watchdog(void)
  						    4 * reset_period) / 4;
  	}
+#ifndef CONFIG_WATCHDOG_AUTOSTART
+	printf("WDT:   Not starting\n");
+	return 0;
+#else
  	ret = wdt_start(gd->watchdog_dev, timeout * 1000, 0);
  	if (ret != 0) {
  		printf("WDT:   Failed to start\n");

drivers/watchdog/wdt-uclass.c int initr_watchdog(void) · line 69

Quoted 3 lines
drivers/watchdog/wdt-uclass.c +1 -0
@@ -61,6 +67,7 @@ int initr_watchdog(void)
  	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
  	return 0;
+#endif

Please use this instead here:

	if (CONFIG_IS_ENABLED(WATCHDOG_AUTOSTART)) {
	...

Thanks,
Stefan

Quoted 7 lines

drivers/watchdog/wdt-uclass.c int initr_watchdog(void)

Quoted 3 lines
drivers/watchdog/wdt-uclass.c +0 -0
  }
  int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
 

Viele Gr??e,
Stefan

I have fixed these issues in V2.

#6 lore raw

PATCH 3/4 watchdog: Allow to use CONFIG_WDT without starting watchdog

Quoted 96 lines · Pali Roh?r
Quoted 95 lines · On Tuesday 09 March 2021 12:33:24 Stefan Roese wrote:
Quoted 2 lines · Pali Roh?r

In some cases it is useful to compile support for U-Boot command 'wdt' without starting HW watchdog in early U-Boot phase. For example when user

Nitpicking:
when "the" user

Quoted 4 lines

want to start watchdog only on demand by some boot script.

This change adds a new compile option WATCHDOG_AUTOSTART to control whether U-Boot should automatically start watchdog during init phase or not.

start "the" watchdog

Quoted 2 lines

This option is enabled by default as it was was default behavior prior

as it was the default

Quoted 37 lines

introducing this new change. When compiling U-Boot users can decide to turn this option off.

---
   drivers/watchdog/Kconfig      | 13 +++++++++++++
   drivers/watchdog/wdt-uclass.c |  7 +++++++
   2 files changed, 20 insertions(+)
drivers/watchdog/Kconfig +13 -0
index 602ccbe41c00..aa76a8f2d239 100644
@@ -9,6 +9,19 @@ config WATCHDOG
   	  this option if you want to service enabled watchdog by U-Boot. Disable
   	  this option if you want U-Boot to start watchdog but never service it.
+config WATCHDOG_AUTOSTART
+	bool "Automatically start watchdog timer"
+	depends on WDT
+	default y
+	help
+	  Automatically start watchdog timer and start servicing it during
+	  init phase. Enabled by default. Disable this option if you want
+	  to compile U-Boot with CONFIG_WDT support but do not want to
+	  activate watchdog, like when CONFIG_WDT option is disabled. You
+	  would be able to start watchdog manually by 'wdt' command. Useful
+	  when you want to have support for 'wdt' command but do not want
+	  to have watchdog enabled by default.
+
   config WATCHDOG_TIMEOUT_MSECS
   	int "Watchdog timeout in msec"
   	default 128000 if ARCH_MX25 || ARCH_MX31 || ARCH_MX5 || ARCH_MX6
drivers/watchdog/wdt-uclass.c +0 -0
index 7500b3ed90e3..00a408bf5cc5 100644

drivers/watchdog/wdt-uclass.c static ulong reset_period = 1000; · line 32

Quoted 6 lines
drivers/watchdog/wdt-uclass.c +2 -0
@@ -27,7 +27,9 @@ static ulong reset_period = 1000;
   int initr_watchdog(void)
   {
   	u32 timeout = WATCHDOG_TIMEOUT_SECS;
+#ifdef CONFIG_WATCHDOG_AUTOSTART
   	int ret;
+#endif

Please don't add more #ifdef's if possible, see below...

Quoted 13 lines
drivers/watchdog/wdt-uclass.c +4 -0
   	/*
   	 * Init watchdog: This will call the probe function of the
@@ -51,6 +53,10 @@ int initr_watchdog(void)
   						    4 * reset_period) / 4;
   	}
+#ifndef CONFIG_WATCHDOG_AUTOSTART
+	printf("WDT:   Not starting\n");
+	return 0;
+#else
   	ret = wdt_start(gd->watchdog_dev, timeout * 1000, 0);
   	if (ret != 0) {
   		printf("WDT:   Failed to start\n");

drivers/watchdog/wdt-uclass.c int initr_watchdog(void) · line 69

Quoted 3 lines
drivers/watchdog/wdt-uclass.c +1 -0
@@ -61,6 +67,7 @@ int initr_watchdog(void)
   	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
   	return 0;
+#endif

Please use this instead here:

	if (CONFIG_IS_ENABLED(WATCHDOG_AUTOSTART)) {
	...

Thanks,
Stefan

Quoted 3 lines
drivers/watchdog/wdt-uclass.c +0 -0
   }
   int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
 
Quoted 4 lines
Quoted 2 lines

Viele Gr??e,
Stefan

I have fixed these issues in V2.

Thanks.

Could you please next time when sending an updated patch series / version include the tags, like my RB tag? As patchwork collects these automatically and now I need to re-send them again - which I will do this time. ;)

Thanks,
Stefan

#18 lore raw

PATCH v2 1/4 watchdog: Set/unset GD_FLG_WDT_READY flag in wdt_start()/wdt_stop()

In reply to Pali Rohár
Quoted 8 lines · Pali Roh?r

Watchdog is ready after successful call of ops->start() callback in wdt_start() function. And is stopped after successful call of ops->stop() callback in wdt_stop function.

So move setting of GD_FLG_WDT_READY flag from initr_watchdog() function to wdt_start() and ensure that GD_FLG_WDT_READY flag is unset in wdt_stop() function.

Quoted 5 lines

This change ensures that GD_FLG_WDT_READY flag is set only when watchdog is running. And ensures that flag is also also when watchdog was started not only by initr_watchdog() call (e.g. by U-Boot 'wdt' command).

Thanks,
Stefan

Quoted 41 lines
---
  drivers/watchdog/wdt-uclass.c | 15 ++++++++++++---
  1 file changed, 12 insertions(+), 3 deletions(-)
drivers/watchdog/wdt-uclass.c +7 -2
index 28f7918c4673..3f707f61f74f 100644
@@ -51,7 +51,6 @@ int initr_watchdog(void)
  	}
 
  	wdt_start(gd->watchdog_dev, timeout * 1000, 0);
-	gd->flags |= GD_FLG_WDT_READY;
  	printf("WDT:   Started with%s servicing (%ds timeout)\n",
  	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
 
@@ -61,21 +60,31 @@ int initr_watchdog(void)
  int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
  {
  	const struct wdt_ops *ops = device_get_ops(dev);
+	int ret;
 
  	if (!ops->start)
  		return -ENOSYS;
 
-	return ops->start(dev, timeout_ms, flags);
+	ret = ops->start(dev, timeout_ms, flags);
+	if (ret == 0)
+		gd->flags |= GD_FLG_WDT_READY;
+
+	return ret;
  }
 
  int wdt_stop(struct udevice *dev)
  {
  	const struct wdt_ops *ops = device_get_ops(dev);
+	int ret;
 
  	if (!ops->stop)
  		return -ENOSYS;

drivers/watchdog/wdt-uclass.c int initr_watchdog(void) · line 90

Quoted 10 lines
drivers/watchdog/wdt-uclass.c +5 -1
 
-	return ops->stop(dev);
+	ret = ops->stop(dev);
+	if (ret == 0)
+		gd->flags &= ~GD_FLG_WDT_READY;
+
+	return ret;
  }
 
  int wdt_reset(struct udevice *dev)

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
#13 lore raw

PATCH v2 2/4 watchdog: Show error message when initr_watchdog() cannot start watchdog

In reply to Pali Rohár
Quoted 5 lines · Pali Roh?r

Function wdt_start() may fail. So in initr_watchdog() function check return value of wdt_start() call and print error message when watchdog starting failed.

Thanks,
Stefan

Quoted 21 lines
---
  drivers/watchdog/wdt-uclass.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/watchdog/wdt-uclass.c +1 -0
index 3f707f61f74f..7500b3ed90e3 100644
@@ -27,6 +27,7 @@ static ulong reset_period = 1000;
  int initr_watchdog(void)
  {
  	u32 timeout = WATCHDOG_TIMEOUT_SECS;
+	int ret;
 
  	/*
  	 * Init watchdog: This will call the probe function of the
@@ -50,7 +51,12 @@ int initr_watchdog(void)
  						    4 * reset_period) / 4;
  	}
 

drivers/watchdog/wdt-uclass.c int initr_watchdog(void) · line 62

Quoted 10 lines
drivers/watchdog/wdt-uclass.c +6 -1
-	wdt_start(gd->watchdog_dev, timeout * 1000, 0);
+	ret = wdt_start(gd->watchdog_dev, timeout * 1000, 0);
+	if (ret != 0) {
+		printf("WDT:   Failed to start\n");
+		return 0;
+	}
+
  	printf("WDT:   Started with%s servicing (%ds timeout)\n",
  	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
 

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
#15 lore raw

PATCH v2 3/4 watchdog: Allow to use CONFIG_WDT without starting watchdog

In reply to Pali Rohár
Quoted 4 lines · Pali Roh?r

In some cases it is useful to compile support for U-Boot command 'wdt' without starting HW watchdog in early U-Boot phase. For example when the user want to start the watchdog only on demand by some boot script.

Quoted 8 lines

This change adds a new compile option WATCHDOG_AUTOSTART to control whether U-Boot should automatically start the watchdog during init phase or not.

This option is enabled by default as it was the default behavior prior introducing this new change. When compiling U-Boot users can decide to turn this option off.

Thanks,
Stefan

Quoted 36 lines
---
  drivers/watchdog/Kconfig      | 13 +++++++++++++
  drivers/watchdog/wdt-uclass.c |  5 +++++
  2 files changed, 18 insertions(+)
drivers/watchdog/Kconfig +13 -0
index 602ccbe41c00..aa76a8f2d239 100644
@@ -9,6 +9,19 @@ config WATCHDOG
  	  this option if you want to service enabled watchdog by U-Boot. Disable
  	  this option if you want U-Boot to start watchdog but never service it.
 
+config WATCHDOG_AUTOSTART
+	bool "Automatically start watchdog timer"
+	depends on WDT
+	default y
+	help
+	  Automatically start watchdog timer and start servicing it during
+	  init phase. Enabled by default. Disable this option if you want
+	  to compile U-Boot with CONFIG_WDT support but do not want to
+	  activate watchdog, like when CONFIG_WDT option is disabled. You
+	  would be able to start watchdog manually by 'wdt' command. Useful
+	  when you want to have support for 'wdt' command but do not want
+	  to have watchdog enabled by default.
+
  config WATCHDOG_TIMEOUT_MSECS
  	int "Watchdog timeout in msec"
  	default 128000 if ARCH_MX25 || ARCH_MX31 || ARCH_MX5 || ARCH_MX6
drivers/watchdog/wdt-uclass.c +0 -0
index 7500b3ed90e3..0603ffbd36d9 100644
@@ -51,6 +51,11 @@ int initr_watchdog(void)
  						    4 * reset_period) / 4;

drivers/watchdog/wdt-uclass.c int initr_watchdog(void) · line 61

Quoted 10 lines
drivers/watchdog/wdt-uclass.c +5 -0
  	}
 
+	if (!CONFIG_IS_ENABLED(WATCHDOG_AUTOSTART)) {
+		printf("WDT:   Not starting\n");
+		return 0;
+	}
+
  	ret = wdt_start(gd->watchdog_dev, timeout * 1000, 0);
  	if (ret != 0) {
  		printf("WDT:   Failed to start\n");

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
#17 lore raw

PATCH v2 4/4 arm: mvebu: Espressobin: Enable watchdog support but do not start it

In reply to Pali Rohár
Quoted 12 lines · Pali Roh?r

Espressobin had disabled watchdog support (CONFIG_WDT) because older stable Linux kernel versions (which are used by current stable OpenWRT and Debian versions) do not have support for Armada 3700 watchdog driver. Therefore they are not able to periodically kick watchdog so Espressobin enter into boot loop.

This change enable CONFIG_WDT, CONFIG_WDT_ARMADA_37XX and CONFIG_CMD_WDT options which add support for U-Boot 'wdt' command. And unset new CONFIG_WATCHDOG_AUTOSTART option which cause that watchdog is not automatically started by U-Boot during init phase, like when CONFIG_WDT option is not set at all.

Quoted 7 lines

So with this change, U-Boot on Espressobin would have working 'wdt' command which can be used from boot scripts (e.g. for enabling watchdog prior new Linux booting kernel). But default behavior of watchdog status stays unchanged, U-Boot does not start watchdog on Espressobin during its init phase.

Thanks,
Stefan

Quoted 18 lines
---
  configs/mvebu_espressobin-88f3720_defconfig | 4 ++++
  1 file changed, 4 insertions(+)
configs/mvebu_espressobin-88f3720_defconfig +1 -0
index c791f98dfea5..20aa21b06b3d 100644
@@ -32,6 +32,7 @@ CONFIG_CMD_MMC=y
  CONFIG_CMD_PCI=y
  CONFIG_CMD_SPI=y
  CONFIG_CMD_USB=y
+CONFIG_CMD_WDT=y
  CONFIG_CMD_TFTPPUT=y
  CONFIG_CMD_CACHE=y
  CONFIG_CMD_TIME=y

configs/mvebu_espressobin-88f3720_defconfig CONFIG_USB_ETHER_ASIX=y · line 96

Quoted 8 lines
configs/mvebu_espressobin-88f3720_defconfig +3 -0
@@ -88,5 +89,8 @@ CONFIG_USB_ETHER_ASIX=y
  CONFIG_USB_ETHER_MCS7830=y
  CONFIG_USB_ETHER_RTL8152=y
  CONFIG_USB_ETHER_SMSC95XX=y
+# CONFIG_WATCHDOG_AUTOSTART is not set
+CONFIG_WDT=y
+CONFIG_WDT_ARMADA_37XX=y
  CONFIG_SHA1=y
  CONFIG_SHA256=y

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
#7 lore raw

PATCH 3/4 watchdog: Allow to use CONFIG_WDT without starting watchdog

In reply to Stefan Roese
Quoted 104 lines · On Tuesday 09 March 2021 17:12:40 Stefan Roese wrote:
Quoted 96 lines · Pali Roh?r
Quoted 95 lines · On Tuesday 09 March 2021 12:33:24 Stefan Roese wrote:
Quoted 2 lines · Pali Roh?r

In some cases it is useful to compile support for U-Boot command 'wdt' without starting HW watchdog in early U-Boot phase. For example when user

Nitpicking:
when "the" user

Quoted 4 lines

want to start watchdog only on demand by some boot script.

This change adds a new compile option WATCHDOG_AUTOSTART to control whether U-Boot should automatically start watchdog during init phase or not.

start "the" watchdog

Quoted 2 lines

This option is enabled by default as it was was default behavior prior

as it was the default

Quoted 37 lines

introducing this new change. When compiling U-Boot users can decide to turn this option off.

---
   drivers/watchdog/Kconfig      | 13 +++++++++++++
   drivers/watchdog/wdt-uclass.c |  7 +++++++
   2 files changed, 20 insertions(+)
drivers/watchdog/Kconfig +13 -0
index 602ccbe41c00..aa76a8f2d239 100644
@@ -9,6 +9,19 @@ config WATCHDOG
   	  this option if you want to service enabled watchdog by U-Boot. Disable
   	  this option if you want U-Boot to start watchdog but never service it.
+config WATCHDOG_AUTOSTART
+	bool "Automatically start watchdog timer"
+	depends on WDT
+	default y
+	help
+	  Automatically start watchdog timer and start servicing it during
+	  init phase. Enabled by default. Disable this option if you want
+	  to compile U-Boot with CONFIG_WDT support but do not want to
+	  activate watchdog, like when CONFIG_WDT option is disabled. You
+	  would be able to start watchdog manually by 'wdt' command. Useful
+	  when you want to have support for 'wdt' command but do not want
+	  to have watchdog enabled by default.
+
   config WATCHDOG_TIMEOUT_MSECS
   	int "Watchdog timeout in msec"
   	default 128000 if ARCH_MX25 || ARCH_MX31 || ARCH_MX5 || ARCH_MX6
drivers/watchdog/wdt-uclass.c +0 -0
index 7500b3ed90e3..00a408bf5cc5 100644

drivers/watchdog/wdt-uclass.c static ulong reset_period = 1000; · line 32

Quoted 6 lines
drivers/watchdog/wdt-uclass.c +2 -0
@@ -27,7 +27,9 @@ static ulong reset_period = 1000;
   int initr_watchdog(void)
   {
   	u32 timeout = WATCHDOG_TIMEOUT_SECS;
+#ifdef CONFIG_WATCHDOG_AUTOSTART
   	int ret;
+#endif

Please don't add more #ifdef's if possible, see below...

Quoted 13 lines
drivers/watchdog/wdt-uclass.c +4 -0
   	/*
   	 * Init watchdog: This will call the probe function of the
@@ -51,6 +53,10 @@ int initr_watchdog(void)
   						    4 * reset_period) / 4;
   	}
+#ifndef CONFIG_WATCHDOG_AUTOSTART
+	printf("WDT:   Not starting\n");
+	return 0;
+#else
   	ret = wdt_start(gd->watchdog_dev, timeout * 1000, 0);
   	if (ret != 0) {
   		printf("WDT:   Failed to start\n");

drivers/watchdog/wdt-uclass.c int initr_watchdog(void) · line 69

Quoted 3 lines
drivers/watchdog/wdt-uclass.c +1 -0
@@ -61,6 +67,7 @@ int initr_watchdog(void)
   	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
   	return 0;
+#endif

Please use this instead here:

	if (CONFIG_IS_ENABLED(WATCHDOG_AUTOSTART)) {
	...

Thanks,
Stefan

Quoted 3 lines
drivers/watchdog/wdt-uclass.c +0 -0
   }
   int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
 
Quoted 4 lines
Quoted 2 lines

Viele Gr??e,
Stefan

I have fixed these issues in V2.

Thanks.

Quoted 7 lines

Could you please next time when sending an updated patch series / version include the tags, like my RB tag? As patchwork collects these automatically and now I need to re-send them again - which I will do this time. ;)

Thanks,
Stefan

Ok, no problem!

#19 lore raw

PATCH v2 1/4 watchdog: Set/unset GD_FLG_WDT_READY flag in wdt_start()/wdt_stop()

In reply to Pali Rohár
Quoted 8 lines · Pali Roh?r

Watchdog is ready after successful call of ops->start() callback in wdt_start() function. And is stopped after successful call of ops->stop() callback in wdt_stop function.

So move setting of GD_FLG_WDT_READY flag from initr_watchdog() function to wdt_start() and ensure that GD_FLG_WDT_READY flag is unset in wdt_stop() function.

Quoted 5 lines

This change ensures that GD_FLG_WDT_READY flag is set only when watchdog is running. And ensures that flag is also also when watchdog was started not only by initr_watchdog() call (e.g. by U-Boot 'wdt' command).

Applied to u-boot-marvell/master (whole series)

Thanks,
Stefan

Quoted 41 lines
---
  drivers/watchdog/wdt-uclass.c | 15 ++++++++++++---
  1 file changed, 12 insertions(+), 3 deletions(-)
drivers/watchdog/wdt-uclass.c +7 -2
index 28f7918c4673..3f707f61f74f 100644
@@ -51,7 +51,6 @@ int initr_watchdog(void)
  	}
 
  	wdt_start(gd->watchdog_dev, timeout * 1000, 0);
-	gd->flags |= GD_FLG_WDT_READY;
  	printf("WDT:   Started with%s servicing (%ds timeout)\n",
  	       IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout);
 
@@ -61,21 +60,31 @@ int initr_watchdog(void)
  int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
  {
  	const struct wdt_ops *ops = device_get_ops(dev);
+	int ret;
 
  	if (!ops->start)
  		return -ENOSYS;
 
-	return ops->start(dev, timeout_ms, flags);
+	ret = ops->start(dev, timeout_ms, flags);
+	if (ret == 0)
+		gd->flags |= GD_FLG_WDT_READY;
+
+	return ret;
  }
 
  int wdt_stop(struct udevice *dev)
  {
  	const struct wdt_ops *ops = device_get_ops(dev);
+	int ret;
 
  	if (!ops->stop)
  		return -ENOSYS;

drivers/watchdog/wdt-uclass.c int initr_watchdog(void) · line 90

Quoted 10 lines
drivers/watchdog/wdt-uclass.c +5 -1
 
-	return ops->stop(dev);
+	ret = ops->stop(dev);
+	if (ret == 0)
+		gd->flags &= ~GD_FLG_WDT_READY;
+
+	return ret;
  }
 
  int wdt_reset(struct udevice *dev)

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de