public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH v1] wdt: Add a glue driver for watchdog
Date: Wed,  5 Jul 2017 20:45:43 +0300	[thread overview]
Message-ID: <20170705174543.72997-1-andriy.shevchenko@linux.intel.com> (raw)

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@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

             reply	other threads:[~2017-07-05 17:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-05 17:45 Andy Shevchenko [this message]
2017-07-05 19:56 ` [U-Boot] [U-Boot,RFC,v1] wdt: Add a glue driver for watchdog Heinrich Schuchardt
2017-07-05 19:58   ` Andy Shevchenko
2017-07-05 20:49 ` Heinrich Schuchardt

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=20170705174543.72997-1-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=u-boot@lists.denx.de \
    /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