Skip to contentSkip to conversation

wdt: Add a glue driver for watchdog

RFC PATCH In review Andy Shevchenko 2 participants 4 messages Jul 5, 2017 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 wdt: Add a glue driver for watchdog

This driver enables first found watchdog as a system one and uses it as a system hardware watchdog device by providing hw_watchdog_reset(), hw_watchdog_disable() and void hw_watchdog_init() hooks.

---

This is not a working solution, just an opinion to which direction we might go with ugly broken WDT class.

Feel free to ignore, drop, modify, etc.

 drivers/watchdog/Kconfig  |  8 +++++++
 drivers/watchdog/Makefile |  1 +
 drivers/watchdog/wdt-hw.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+)
 create mode 100644 drivers/watchdog/wdt-hw.c
drivers/watchdog/Kconfig +8 -0
index 0ed5aa987f..4837e73565 100644
@@ -35,6 +35,14 @@ config WDT
 	  What exactly happens when the timer expires is up to a particular
 	  device/driver.
 
+config WDT_HW
+	bool "Enable hardware Watchdog Timer"
+	depends on WDT
+	select HW_WATCHDOG
+	help
+		Enable hardware Watchdog Timer. This is a glue driver to enable
+		first found watchdog device as a system one.
+
 config WDT_SANDBOX
 	bool "Enable Watchdog Timer support for Sandbox"
 	depends on SANDBOX && WDT
drivers/watchdog/Makefile +1 -0
index 0ad16f661e..c4a297e88b 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.o
 obj-$(CONFIG_DESIGNWARE_WATCHDOG) += designware_wdt.o
 obj-$(CONFIG_ULP_WATCHDOG) += ulp_wdog.o
 obj-$(CONFIG_WDT) += wdt-uclass.o
+obj-$(CONFIG_WDT_HW) += wdt-hw.o
 obj-$(CONFIG_WDT_SANDBOX) += sandbox_wdt.o
 obj-$(CONFIG_WDT_ASPEED) += ast_wdt.o
 obj-$(CONFIG_WDT_BCM6345) += bcm6345_wdt.o
drivers/watchdog/wdt-hw.c new file +55 -0

55 lines not on this page · raw message

Signature · 1 line
2.11.0
#1 lore raw
Quoted 73 lines · Andy Shevchenko

This driver enables first found watchdog as a system one and uses it as a system hardware watchdog device by providing hw_watchdog_reset(), hw_watchdog_disable() and void hw_watchdog_init() hooks.

---

This is not a working solution, just an opinion to which direction we might go with ugly broken WDT class.

Feel free to ignore, drop, modify, etc.

 drivers/watchdog/Kconfig  |  8 +++++++
 drivers/watchdog/Makefile |  1 +
 drivers/watchdog/wdt-hw.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+)
 create mode 100644 drivers/watchdog/wdt-hw.c
drivers/watchdog/Kconfig +8 -0
index 0ed5aa987f..4837e73565 100644
@@ -35,6 +35,14 @@ config WDT
 	  What exactly happens when the timer expires is up to a particular
 	  device/driver.
 
+config WDT_HW
+	bool "Enable hardware Watchdog Timer"
+	depends on WDT
+	select HW_WATCHDOG
+	help
+		Enable hardware Watchdog Timer. This is a glue driver to enable
+		first found watchdog device as a system one.
+
 config WDT_SANDBOX
 	bool "Enable Watchdog Timer support for Sandbox"
 	depends on SANDBOX && WDT
drivers/watchdog/Makefile +1 -0
index 0ad16f661e..c4a297e88b 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.o
 obj-$(CONFIG_DESIGNWARE_WATCHDOG) += designware_wdt.o
 obj-$(CONFIG_ULP_WATCHDOG) += ulp_wdog.o
 obj-$(CONFIG_WDT) += wdt-uclass.o
+obj-$(CONFIG_WDT_HW) += wdt-hw.o
 obj-$(CONFIG_WDT_SANDBOX) += sandbox_wdt.o
 obj-$(CONFIG_WDT_ASPEED) += ast_wdt.o
 obj-$(CONFIG_WDT_BCM6345) += bcm6345_wdt.o
drivers/watchdog/wdt-hw.c new file +18 -0
new file mode 100644
index 0000000000..3e98db86c8
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+#include <common.h>
+#include <dm.h>
+#include <wdt.h>
+
+/* Hardware timeout in milliseconds */
+#ifdef CONFIG_WATCHDOG_TIMEOUT_MSECS
+#define WATCHDOG_HEARTBEAT CONFIG_WATCHDOG_TIMEOUT_MSECS
+#else
+#define WATCHDOG_HEARTBEAT 60000
+#endif
+
+static struct udevice *wdt;
+

drivers/watchdog/wdt-hw.c line 28

Quoted 10 lines
drivers/watchdog/wdt-hw.c new file +10 -0
+void hw_watchdog_reset(void)
+{
+	int ret;
+
+	if (!wdt)
+		return;
+
+	ret = wdt_reset(wdt);
+	if (ret)
+		printf("Can't reset watchdog device: %d\n", ret);

I would suggest debug() instead of printf().

Imagine this being called from an EFI application in a loop. We wouldn't want to fill the screen with this message.

Best regards

Heinrich Schuchardt

#2 lore raw
Quoted 7 lines · Heinrich Schuchardt
Quoted 5 lines · Andy Shevchenko

This is not a working solution, just an opinion to which direction we might go
with ugly broken WDT class.

Feel free to ignore, drop, modify, etc.

^^^^^^ DISCLAIMER

Quoted 9 lines

drivers/watchdog/wdt-hw.c line 28

Quoted 3 lines
drivers/watchdog/wdt-hw.c new file +3 -0
+	ret = wdt_reset(wdt);
+	if (ret)
+		printf("Can't reset watchdog device: %d\n", ret);

I would suggest debug() instead of printf().

Imagine this being called from an EFI application in a loop. We wouldn't
want to fill the screen with this message.

Thanks for the indeed correct suggestion, though please read a disclaimer above. I gave up on that.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#3 lore raw
In reply to Andy Shevchenko
Quoted 9 lines · Andy Shevchenko

This driver enables first found watchdog as a system one and uses it as a system hardware watchdog device by providing hw_watchdog_reset(), hw_watchdog_disable() and void hw_watchdog_init() hooks.

---

This is not a working solution, just an opinion to which direction we might go with ugly broken WDT class.

We need a watchdog driver to complete the UEFI implementation.

Currently you are only thinking about a hardware watchdog. We do not have hardware watchdog drivers for every board.

I would prefer if we had a software fallback solution that would update the timer ticks when waiting for keyboard or in other loops like network traffic.

Best regards

Heinrich

Quoted 102 lines

Feel free to ignore, drop, modify, etc.

 drivers/watchdog/Kconfig  |  8 +++++++
 drivers/watchdog/Makefile |  1 +
 drivers/watchdog/wdt-hw.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+)
 create mode 100644 drivers/watchdog/wdt-hw.c
drivers/watchdog/Kconfig +8 -0
index 0ed5aa987f..4837e73565 100644
@@ -35,6 +35,14 @@ config WDT
 	  What exactly happens when the timer expires is up to a particular
 	  device/driver.
 
+config WDT_HW
+	bool "Enable hardware Watchdog Timer"
+	depends on WDT
+	select HW_WATCHDOG
+	help
+		Enable hardware Watchdog Timer. This is a glue driver to enable
+		first found watchdog device as a system one.
+
 config WDT_SANDBOX
 	bool "Enable Watchdog Timer support for Sandbox"
 	depends on SANDBOX && WDT
drivers/watchdog/Makefile +1 -0
index 0ad16f661e..c4a297e88b 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.o
 obj-$(CONFIG_DESIGNWARE_WATCHDOG) += designware_wdt.o
 obj-$(CONFIG_ULP_WATCHDOG) += ulp_wdog.o
 obj-$(CONFIG_WDT) += wdt-uclass.o
+obj-$(CONFIG_WDT_HW) += wdt-hw.o
 obj-$(CONFIG_WDT_SANDBOX) += sandbox_wdt.o
 obj-$(CONFIG_WDT_ASPEED) += ast_wdt.o
 obj-$(CONFIG_WDT_BCM6345) += bcm6345_wdt.o
drivers/watchdog/wdt-hw.c new file +55 -0
new file mode 100644
index 0000000000..3e98db86c8
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+#include <common.h>
+#include <dm.h>
+#include <wdt.h>
+
+/* Hardware timeout in milliseconds */
+#ifdef CONFIG_WATCHDOG_TIMEOUT_MSECS
+#define WATCHDOG_HEARTBEAT CONFIG_WATCHDOG_TIMEOUT_MSECS
+#else
+#define WATCHDOG_HEARTBEAT 60000
+#endif
+
+static struct udevice *wdt;
+
+void hw_watchdog_reset(void)
+{
+	int ret;
+
+	if (!wdt)
+		return;
+
+	ret = wdt_reset(wdt);
+	if (ret)
+		printf("Can't reset watchdog device: %d\n", ret);
+}
+
+void hw_watchdog_disable(void)
+{
+	int ret;
+
+	if (!wdt)
+		return;
+
+	ret = wdt_stop(wdt);
+	if (ret)
+		printf("Can't stop watchdog device: %d\n", ret);
+}
+
+void hw_watchdog_init(void)
+{
+	int ret;
+
+	ret = uclass_first_device(UCLASS_WDT, &wdt);
+	if (ret)
+		printf("Can't find watchdog device: %d\n", ret);
+	else {
+		ret = wdt_start(wdt, WATCHDOG_HEARTBEAT * 1000, 0);
+		if (ret)
+			printf("Can't start watchdog device: %d\n", ret);
+	}
+}