linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Wim Van Sebroeck <wim@linux-watchdog.org>,
	Guenter Roeck <linux@roeck-us.net>
Cc: Malin Jonsson <malin.jonsson@ericsson.com>,
	john.jacques@intel.com, linux-watchdog@vger.kernel.org,
	Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: [PATCH] watchdog: iTCO_wdt: Leave running if the watchdog core ping thread is enabled
Date: Fri, 17 Sep 2021 13:15:33 +0300	[thread overview]
Message-ID: <20210917101533.9722-1-mika.westerberg@linux.intel.com> (raw)

The watchdog core can handle pinging of the watchdog before userspace
gets control so we can take advantage of that in iTCO_wdt. This also
allows users to disable the watchdog core ping thread by passing
watchdog.handle_boot_enabled=0 in the kernel command line if needed.

To avoid any unexpected resets we keep the existing functionality of
stopping the watchdog on probe if the watchdog core ping thread is not
enabled in the Kconfig (CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED=n).

Cc: Malin Jonsson <malin.jonsson@ericsson.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/watchdog/iTCO_wdt.c | 42 ++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 8 deletions(-)

diff --git a/drivers/watchdog/iTCO_wdt.c b/drivers/watchdog/iTCO_wdt.c
index 643c6c2d0b72..234494c03df3 100644
--- a/drivers/watchdog/iTCO_wdt.c
+++ b/drivers/watchdog/iTCO_wdt.c
@@ -430,6 +430,27 @@ static unsigned int iTCO_wdt_get_timeleft(struct watchdog_device *wd_dev)
 	return time_left;
 }
 
+static bool iTCO_wdt_set_running(struct iTCO_wdt_private *p)
+{
+	/*
+	 * If the watchdog core is enabled to handle pinging the
+	 * watchdog before userspace takes control we can leave the
+	 * hardware as is.
+	 */
+	if (IS_ENABLED(CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED)) {
+		u16 val;
+
+		/* Bit 11: TCO Timer Halt -> 0 = The TCO timer is * enabled */
+		val = inw(TCO1_CNT(p));
+		if (!(val & BIT(11)))
+			set_bit(WDOG_HW_RUNNING, &p->wddev.status);
+
+		return true;
+	}
+
+	return false;
+}
+
 /*
  *	Kernel Interfaces
  */
@@ -572,15 +593,20 @@ static int iTCO_wdt_probe(struct platform_device *pdev)
 	watchdog_set_drvdata(&p->wddev, p);
 	platform_set_drvdata(pdev, p);
 
-	/* Make sure the watchdog is not running */
-	iTCO_wdt_stop(&p->wddev);
+	if (!iTCO_wdt_set_running(p)) {
+		/* Make sure the watchdog is not running */
+		iTCO_wdt_stop(&p->wddev);
 
-	/* Check that the heartbeat value is within it's range;
-	   if not reset to the default */
-	if (iTCO_wdt_set_timeout(&p->wddev, heartbeat)) {
-		iTCO_wdt_set_timeout(&p->wddev, WATCHDOG_TIMEOUT);
-		dev_info(dev, "timeout value out of range, using %d\n",
-			WATCHDOG_TIMEOUT);
+		/*
+		 * Check that the heartbeat value is within it's range;
+		 * if not reset to the default.
+		 */
+		if (iTCO_wdt_set_timeout(&p->wddev, heartbeat)) {
+			iTCO_wdt_set_timeout(&p->wddev, WATCHDOG_TIMEOUT);
+			dev_info(p->wddev.parent,
+				 "timeout value out of range, using %d\n",
+				 WATCHDOG_TIMEOUT);
+		}
 	}
 
 	watchdog_stop_on_reboot(&p->wddev);
-- 
2.33.0


             reply	other threads:[~2021-09-17 10:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-17 10:15 Mika Westerberg [this message]
2021-09-17 14:31 ` [PATCH] watchdog: iTCO_wdt: Leave running if the watchdog core ping thread is enabled Guenter Roeck
2021-09-17 14:55   ` Mika Westerberg

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=20210917101533.9722-1-mika.westerberg@linux.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=john.jacques@intel.com \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=malin.jonsson@ericsson.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).