mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH v2 2/4] watchdog: add (U)EFI driver
Date: Fri, 15 Feb 2019 13:43:49 +0100	[thread overview]
Message-ID: <20190215124351.30374-3-o.rempel@pengutronix.de> (raw)
In-Reply-To: <20190215124351.30374-1-o.rempel@pengutronix.de>

This driver is using SetWatchdogTimer() UEFI interface and was
tested on iBASE MI991AF Mini-ITX motherboard.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 common/efi/efi.c           |  9 +++++-
 drivers/watchdog/Kconfig   |  6 ++++
 drivers/watchdog/Makefile  |  1 +
 drivers/watchdog/efi_wdt.c | 64 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+), 1 deletion(-)
 create mode 100644 drivers/watchdog/efi_wdt.c

diff --git a/common/efi/efi.c b/common/efi/efi.c
index 1f451a157e..a7b25cbbe2 100644
--- a/common/efi/efi.c
+++ b/common/efi/efi.c
@@ -367,8 +367,15 @@ efi_status_t efi_main(efi_handle_t image, efi_system_table_t *sys_table)
 
 static int efi_core_init(void)
 {
-	struct device_d *dev = device_alloc("efi-cs", DEVICE_ID_SINGLE);
+	struct device_d *dev;
+	int ret;
+
+	dev = device_alloc("efi-cs", DEVICE_ID_SINGLE);
+	ret = platform_device_register(dev);
+	if (ret)
+		return ret;
 
+	dev = device_alloc("efi-wdt", DEVICE_ID_SINGLE);
 	return platform_device_register(dev);
 }
 core_initcall(efi_core_init);
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 02cc0feb61..2793ee93d9 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -22,6 +22,12 @@ config WATCHDOG_AR9344
 	help
 	  Add support for watchdog on the QCA AR9344 SoC.
 
+config WATCHDOG_EFI
+	bool "Generic EFI Watchdog Driver"
+	depends on EFI_BOOTUP
+	help
+	  Add support for the EFI watchdog.
+
 config WATCHDOG_DAVINCI
 	bool "TI Davinci"
 	depends on ARCH_DAVINCI
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index faf06110a3..69189ba1f3 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -1,5 +1,6 @@
 obj-$(CONFIG_WATCHDOG) += wd_core.o
 obj-$(CONFIG_WATCHDOG_AR9344) += ar9344_wdt.o
+obj-$(CONFIG_WATCHDOG_EFI) += efi_wdt.o
 obj-$(CONFIG_WATCHDOG_DAVINCI) += davinci_wdt.o
 obj-$(CONFIG_WATCHDOG_OMAP) += omap_wdt.o
 obj-$(CONFIG_WATCHDOG_MXS28) += im28wd.o
diff --git a/drivers/watchdog/efi_wdt.c b/drivers/watchdog/efi_wdt.c
new file mode 100644
index 0000000000..8e3e51b7a9
--- /dev/null
+++ b/drivers/watchdog/efi_wdt.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ *  Copyright (C) 2019 Oleksij Rempel <o.rempel@pengutronix.de>, Pengutronix
+ */
+
+#include <common.h>
+#include <init.h>
+#include <driver.h>
+#include <efi.h>
+#include <efi/efi.h>
+#include <watchdog.h>
+
+struct efi_wdt_priv {
+	struct watchdog		wd;
+	struct device_d		*dev;
+};
+
+#define to_efi_wdt(h) container_of(h, struct efi_wdt_priv, wd)
+
+static int efi_wdt_set_timeout(struct watchdog *wd, unsigned timeout)
+{
+	struct efi_wdt_priv *priv = to_efi_wdt(wd);
+	efi_status_t efiret;
+
+	efiret = BS->set_watchdog_timer(timeout, 0, 0, NULL);
+	if (EFI_ERROR(efiret)) {
+		dev_err(priv->dev, "filed to set EFI watchdog: %lx\n", efiret);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int efi_wdt_probe(struct device_d *dev)
+{
+	struct efi_wdt_priv *priv;
+	int ret;
+
+	priv = xzalloc(sizeof(*priv));
+
+	priv->wd.set_timeout = efi_wdt_set_timeout;
+	priv->wd.hwdev = dev;
+	priv->dev = dev;
+
+	dev->priv = priv;
+
+	priv->wd.timeout_max = U32_MAX;
+
+	ret = watchdog_register(&priv->wd);
+	if (ret)
+		goto on_error;
+
+	return 0;
+
+on_error:
+	free(priv);
+	return ret;
+}
+
+static struct driver_d efi_wdt_driver = {
+	.name = "efi-wdt",
+	.probe = efi_wdt_probe,
+};
+device_platform_driver(efi_wdt_driver);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2019-02-15 12:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-15 12:43 [PATCH v2 0/4] add (U)EFI watchdog Oleksij Rempel
2019-02-15 12:43 ` [PATCH v2 1/4] efi: add prototype and definition for set_watchdog_timer Oleksij Rempel
2019-02-15 12:43 ` Oleksij Rempel [this message]
2019-02-15 12:43 ` [PATCH v2 3/4] efi_defconfig: enable watchdog support Oleksij Rempel
2019-02-15 12:43 ` [PATCH v2 4/4] Documentation: efi: provide (U)EFI watchdog documentation Oleksij Rempel
2019-02-18  8:54 ` [PATCH v2 0/4] add (U)EFI watchdog Sascha Hauer

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=20190215124351.30374-3-o.rempel@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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