mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Yang <mmyangfl@gmail.com>
To: linux-watchdog@vger.kernel.org
Cc: David Yang <mmyangfl@gmail.com>,
	stable@vger.kernel.org, Wim Van Sebroeck <wim@linux-watchdog.org>,
	Guenter Roeck <linux@roeck-us.net>,
	Jongsung Kim <neidhard.kim@lge.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2] watchdog: sp805: re-enable the clock in the restart handler
Date: Sun, 22 Nov 2026 04:45:25 +0800	[thread overview]
Message-ID: <20261121204528.2435533-1-mmyangfl@gmail.com> (raw)

wdt_restart() fail to reboot the system if the watchdog counter clock
was previously disabled: If userspace cleanly stops the watchdog, the
core calls wdt_disable() which disables wdt->clk. No reset comes.

Re-enable the clock in it as in npcm_wdt. The watchdog .restart()
callback runs in atomic context: get the clock with
devm_clk_get_optional_prepared() at probe time and keep it prepared for
the lifetime of the driver, so the restart handler only needs
clk_enable(), which is safe in atomic context.

Link: https://lore.kernel.org/r/20260911031916.A8E051F000FF@smtp.kernel.org
Fixes: 6c5c0d48b686 ("watchdog: sp805: add restart handler")
Cc: stable@vger.kernel.org
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
v2:
 - include a Fixes tag
 - use clk_enable() in the restart handler
v1: https://lore.kernel.org/r/20261120201029.1685193-1-mmyangfl@gmail.com
 drivers/watchdog/sp805_wdt.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/watchdog/sp805_wdt.c b/drivers/watchdog/sp805_wdt.c
index a14ff7ac0db4..4e4febc52853 100644
--- a/drivers/watchdog/sp805_wdt.c
+++ b/drivers/watchdog/sp805_wdt.c
@@ -138,6 +138,13 @@ wdt_restart(struct watchdog_device *wdd, unsigned long mode, void *cmd)
 {
 	struct sp805_wdt *wdt = watchdog_get_drvdata(wdd);
 
+	/*
+	 * For reset, we start the WDT clock and leave it running.
+	 * The clock was prepared at probe time; only clk_enable() is
+	 * safe in this atomic (restart notifier) context.
+	 */
+	clk_enable(wdt->clk);
+
 	writel_relaxed(UNLOCK, wdt->base + WDTLOCK);
 	writel_relaxed(0, wdt->base + WDTCONTROL);
 	writel_relaxed(0, wdt->base + WDTLOAD);
@@ -156,7 +163,7 @@ static int wdt_config(struct watchdog_device *wdd, bool ping)
 
 	if (!ping) {
 
-		ret = clk_prepare_enable(wdt->clk);
+		ret = clk_enable(wdt->clk);
 		if (ret) {
 			dev_err(&wdt->adev->dev, "clock enable fail");
 			return ret;
@@ -208,7 +215,7 @@ static int wdt_disable(struct watchdog_device *wdd)
 	readl_relaxed(wdt->base + WDTLOCK);
 	spin_unlock(&wdt->lock);
 
-	clk_disable_unprepare(wdt->clk);
+	clk_disable(wdt->clk);
 
 	return 0;
 }
@@ -253,7 +260,11 @@ sp805_wdt_probe(struct amba_device *adev, const struct amba_id *id)
 	 */
 	device_property_read_u64(&adev->dev, "clock-frequency", &rate);
 
-	wdt->clk = devm_clk_get_optional(&adev->dev, NULL);
+	/*
+	 * Keep the clock prepared for the lifetime of the driver:
+	 * wdt_restart() runs in atomic context and may only call clk_enable().
+	 */
+	wdt->clk = devm_clk_get_optional_prepared(&adev->dev, NULL);
 	if (IS_ERR(wdt->clk))
 		return dev_err_probe(&adev->dev, PTR_ERR(wdt->clk), "Clock not found\n");
 
-- 
2.53.0


                 reply	other threads:[~2026-11-21 20:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261121204528.2435533-1-mmyangfl@gmail.com \
    --to=mmyangfl@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=neidhard.kim@lge.com \
    --cc=stable@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®