All of lore.kernel.org
 help / color / mirror / Atom feed
From: advantech.susiteam@gmail.com
To: advantech.susiteam@gmail.com
Cc: wenkai.chung@advantech.com.tw, Susi.Driver@advantech.com,
	Wim Van Sebroeck <wim@linux-watchdog.org>,
	Guenter Roeck <linux@roeck-us.net>,
	linux-kernel@vger.kernel.org, linux-watchdog@vger.kernel.org
Subject: [PATCH 1/5] watchdog: eiois200_wdt: Constructing Advantech EIO-IS200 watchdog driver
Date: Thu,  5 Oct 2023 16:51:19 +0800	[thread overview]
Message-ID: <b627f827d13514c1746beb31bb80db71023e9bb1.1696495372.git.advantech.susiteam@gmail.com> (raw)
In-Reply-To: <cover.1696495372.git.advantech.susiteam@gmail.com>

From: Wenkai <advantech.susiteam@gmail.com>

This is the initial patch that adds the Advantech EIO-IS200 Watchdog
Driver to the kernel. It includes the necessary Makefile and Kconfig
entries to integrate the driver with the watchdog framework. However,
please note that this patch does not yet implement the actual watchdog
functionality. When configuring the kernel using tools like menuconfig,
as all other eiois200 series drivers, it cannot be selected Y as built
in, you can select M to build it as a module or select N to exclude it.

Please also be aware that this driver is a sub-driver of
`drivers/mfd/eiois200_core`. Therefore, it is required for the proper
compilation of the Advantech EIO-IS200 support. Failing to include this
driver may result in compilation errors.

Signed-off-by: Wenkai <advantech.susiteam@gmail.com>
---
 drivers/watchdog/Kconfig        |  14 ++++
 drivers/watchdog/Makefile       |   1 +
 drivers/watchdog/eiois200_wdt.c | 124 ++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+)
 create mode 100644 drivers/watchdog/eiois200_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index ee97d89dfc11..218c90714830 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -1079,6 +1079,20 @@ config ADVANTECH_EC_WDT
 		This driver supports Advantech products with ITE based Embedded Controller.
 		It does not support Advantech products with other ECs or without EC.
 
+config EIOIS200_WDT
+	tristate "Advantech EIO IS-200 Watchdog Timer"
+	depends on X86 && m
+	default m
+	select MFD_EIOIS200
+	help
+	  This is the driver for the hardware watchdog on the EIO IS-200 EC
+	  chip as used in Advantech boards (and likely others).
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called eiois200_wdt.
+
+	  Most people will say M.
+
 config ALIM1535_WDT
 	tristate "ALi M1535 PMU Watchdog Timer"
 	depends on X86 && PCI
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 3633f5b98236..713872a4f7de 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -103,6 +103,7 @@ obj-$(CONFIG_SUNPLUS_WATCHDOG) += sunplus_wdt.o
 obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
 obj-$(CONFIG_ADVANTECH_WDT) += advantechwdt.o
 obj-$(CONFIG_ADVANTECH_EC_WDT) += advantech_ec_wdt.o
+obj-$(CONFIG_EIOIS200_WDT) += eiois200_wdt.o
 obj-$(CONFIG_ALIM1535_WDT) += alim1535_wdt.o
 obj-$(CONFIG_ALIM7101_WDT) += alim7101_wdt.o
 obj-$(CONFIG_EBC_C384_WDT) += ebc-c384_wdt.o
diff --git a/drivers/watchdog/eiois200_wdt.c b/drivers/watchdog/eiois200_wdt.c
new file mode 100644
index 000000000000..bf132a75a2ec
--- /dev/null
+++ b/drivers/watchdog/eiois200_wdt.c
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Advantech EIO-IS200 Watchdog Driver
+ *
+ * Copyright (C) 2023 Advantech Co., Ltd.
+ * Author: wenkai <advantech.susiteam@gmail.com>
+ */
+
+#include <linux/mfd/core.h>
+#include <linux/reboot.h>
+#include <linux/uaccess.h>
+#include <linux/watchdog.h>
+
+#include "../mfd/eiois200.h"
+
+#define WATCHDOG_TIMEOUT	60
+#define WATCHDOG_PRETIMEOUT	10
+
+static struct _wdt {
+	u32	support;
+	long	last_time;
+	struct	regmap  *iomap;
+	struct	device *dev;
+} wdt;
+
+/* Pointer to the eiois200_core device structure */
+static struct eiois200_dev *eiois200_dev;
+
+static struct watchdog_info wdinfo = {
+	.identity = KBUILD_MODNAME,
+	.options  = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING |
+		    WDIOF_MAGICCLOSE,
+};
+
+static struct watchdog_device wddev = {
+	.info	     = &wdinfo,
+	.max_timeout = 0x7FFF,
+	.min_timeout = 1,
+};
+
+static int wdt_set_timeout(struct watchdog_device *dev,
+			   unsigned int _timeout)
+{
+	dev->timeout = _timeout;
+	dev_dbg(wdt.dev, "Set timeout: %d\n", _timeout);
+
+	return 0;
+}
+
+static int wdt_start(struct watchdog_device *dev)
+{
+	return 0;
+}
+
+static int wdt_stop(struct watchdog_device *dev)
+{
+	return 0;
+}
+
+static int wdt_ping(struct watchdog_device *dev)
+{
+	return 0;
+}
+
+static unsigned int wdt_get_timeleft(struct watchdog_device *dev)
+{
+	return 0;
+}
+
+static const struct watchdog_ops wdt_ops = {
+	.owner		= THIS_MODULE,
+	.start		= wdt_start,
+	.stop		= wdt_stop,
+	.ping		= wdt_ping,
+	.set_timeout	= wdt_set_timeout,
+	.get_timeleft	= wdt_get_timeleft,
+};
+
+static int wdt_probe(struct platform_device *pdev)
+{
+	int ret = 0;
+	struct device *dev = &pdev->dev;
+
+	/* Contact eiois200_core */
+	eiois200_dev = dev_get_drvdata(dev->parent);
+	if (!eiois200_dev)
+		return dev_err_probe(dev, ret,
+				     "Error contact eiois200_core %d\n", ret);
+
+	wdt.dev = dev;
+	wdt.iomap = dev_get_regmap(dev->parent, NULL);
+	if (!wdt.iomap)
+		return dev_err_probe(dev, -ENOMEM, "Query parent regmap fail\n");
+
+	/* Inform watchdog info */
+	wddev.ops = &wdt_ops;
+	ret = watchdog_init_timeout(&wddev, wddev.timeout, dev);
+	if (ret)
+		return dev_err_probe(dev, ret, "Init timeout fail\n");
+
+	watchdog_stop_on_reboot(&wddev);
+
+	watchdog_stop_on_unregister(&wddev);
+
+	/* Register watchdog */
+	ret = devm_watchdog_register_device(dev, &wddev);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Cannot register watchdog device (err: %d)\n",
+				     ret);
+
+	return 0;
+}
+
+static struct platform_driver eiois200_wdt_driver = {
+	.driver = {
+		.name  = "eiois200_wdt",
+	},
+};
+module_platform_driver_probe(eiois200_wdt_driver, wdt_probe);
+
+MODULE_AUTHOR("wenkai <advantech.susiteam@gmail.com>");
+MODULE_DESCRIPTION("Watchdog interface for Advantech EIO-IS200 embedded controller");
+MODULE_LICENSE("GPL");
-- 
2.34.1


  reply	other threads:[~2023-10-05 13:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-05  8:51 [PATCH 0/5] watchdog: eiois200_wdt: Add EIO-IS200 Watchdog Driver advantech.susiteam
2023-10-05  8:51 ` advantech.susiteam [this message]
2023-10-05 23:33   ` [PATCH 1/5] watchdog: eiois200_wdt: Constructing Advantech EIO-IS200 watchdog driver kernel test robot
2023-10-05  8:51 ` [PATCH 2/5] watchdog: eiois200_wdt: Add PMC support with eiois200_core advantech.susiteam
2023-10-05  8:51 ` [PATCH 3/5] watchdog: eiois200_wdt: Implement basic watchdog functionalities advantech.susiteam
2023-10-05  8:51 ` [PATCH 4/5] watchdog: eiois200_wdt: Enhanced watchdog functionality and pretimeout advantech.susiteam
2023-10-05  8:51 ` [PATCH 5/5] watchdog: eiois200_wdt: Enhanced IRQ trigger behavior advantech.susiteam
2023-10-06  3:02 ` [PATCH 0/5] watchdog: eiois200_wdt: Add EIO-IS200 Watchdog Driver Guenter Roeck
2023-10-06  9:27   ` Wenkai
2023-10-06 14:16     ` Guenter Roeck
2023-10-11  4:08       ` Wenkai
2023-10-11 15:05         ` Guenter Roeck
2023-10-12  7:56           ` Wenkai

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=b627f827d13514c1746beb31bb80db71023e9bb1.1696495372.git.advantech.susiteam@gmail.com \
    --to=advantech.susiteam@gmail.com \
    --cc=Susi.Driver@advantech.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=wenkai.chung@advantech.com.tw \
    --cc=wim@linux-watchdog.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.