[U-Boot] [RFC PATCH v1] wdt: Add a glue driver for watchdog
Andy Shevchenko
andriy.shevchenko at linux.intel.com
Wed Jul 5 17:45:43 UTC 2017
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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko at linux.intel.com>
---
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
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 0ed5aa987f..4837e73565 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -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
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 0ad16f661e..c4a297e88b 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -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
diff --git a/drivers/watchdog/wdt-hw.c b/drivers/watchdog/wdt-hw.c
new file mode 100644
index 0000000000..3e98db86c8
--- /dev/null
+++ b/drivers/watchdog/wdt-hw.c
@@ -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);
+ }
+}
--
2.11.0
More information about the U-Boot
mailing list