Devicetree
 help / color / mirror / Atom feed
From: Henry Qin <henry.qin@starfivetech.com>
To: Wim Van Sebroeck <wim@linux-watchdog.org>,
	Guenter Roeck <linux@roeck-us.net>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Xingyu Wu <xingyu.wu@starfivetech.com>,
	Ziv Xu <ziv.xu@starfivetech.com>
Cc: Henry Qin <henry.qin@starfivetech.com>,
	linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] watchdog: starfive: Add jhb100 support
Date: Fri,  4 Dec 2026 13:53:36 +0000	[thread overview]
Message-ID: <20261204135336.632-4-henry.qin@starfivetech.com> (raw)
In-Reply-To: <20261204135336.632-1-henry.qin@starfivetech.com>

Add support for the watchdog in the StarFive JHB100 SoC.

Compared to JH7110, the JHB100 watchdog uses a different register
layout and lock key. The counter is restarted by writing a key to the
RESTART register, and it is reloaded from LOAD when the watchdog is
enabled and whenever the restart key is written.

The CONTROL register is set up so that the watchdog resets the system
on the first timeout.

Signed-off-by: Henry Qin <henry.qin@starfivetech.com>
---
 drivers/watchdog/Kconfig        |  4 +--
 drivers/watchdog/starfive-wdt.c | 53 ++++++++++++++++++++++++++++++++-
 2 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 3abbff003fce..88cfee265209 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -2169,8 +2169,8 @@ config STARFIVE_WATCHDOG
 	select WATCHDOG_CORE
 	default ARCH_STARFIVE
 	help
-	  Say Y here to support the watchdog of StarFive JH7100 and JH7110
-	  SoC. This driver can also be built as a module if choose M.
+	  Say Y here to support the watchdog of StarFive JH7100, JH7110 and
+	  JHB100 SoC. This driver can also be built as a module if choose M.
 
 # S390 Architecture
 
diff --git a/drivers/watchdog/starfive-wdt.c b/drivers/watchdog/starfive-wdt.c
index 24909afacd4e..045b922c76ab 100644
--- a/drivers/watchdog/starfive-wdt.c
+++ b/drivers/watchdog/starfive-wdt.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2022 StarFive Technology Co., Ltd.
  */
 
+#include <linux/bits.h>
 #include <linux/clk.h>
 #include <linux/iopoll.h>
 #include <linux/module.h>
@@ -41,16 +42,38 @@
 #define STARFIVE_WDT_JH7110_IMS		0x014
 #define STARFIVE_WDT_JH7110_LOCK	0xc00	/* write 0x1ACCE551 to unlock */
 
+/*
+ * JHB100 Watchdog register define
+ *
+ * The counter is reloaded from LOAD when the watchdog is enabled and
+ * whenever the restart key is written to RESTART.
+ */
+#define STARFIVE_WDT_JHB100_CONTROL	0x000	/*
+						 * [0]: watchdog enable
+						 * [1]: 1 mean reset on the first timeout
+						 * [4]: reset enable
+						 */
+#define STARFIVE_WDT_JHB100_LOAD	0x00c
+#define STARFIVE_WDT_JHB100_VALUE	0x010
+#define STARFIVE_WDT_JHB100_RESTART	0x014	/* write 0xb8c12ba8 to restart the counter */
+#define STARFIVE_WDT_JHB100_LOCK	0x018	/* write 0xa7a0e19c to unlock */
+
 /* WDOGCONTROL */
 #define STARFIVE_WDT_ENABLE			0x1
 #define STARFIVE_WDT_EN_SHIFT			0
 #define STARFIVE_WDT_RESET_EN			0x1
 #define STARFIVE_WDT_JH7100_RST_EN_SHIFT	0
 #define STARFIVE_WDT_JH7110_RST_EN_SHIFT	1
+#define STARFIVE_WDT_JHB100_RST_EN_SHIFT	4
+#define STARFIVE_WDT_JHB100_RST_MODE		BIT(1)
 
 /* WDOGLOCK */
 #define STARFIVE_WDT_JH7100_UNLOCK_KEY		0x378f0765
 #define STARFIVE_WDT_JH7110_UNLOCK_KEY		0x1acce551
+#define STARFIVE_WDT_JHB100_UNLOCK_KEY		0xa7a0e19c
+
+/* WDOGRESTART */
+#define STARFIVE_WDT_JHB100_RESTART_KEY		0xb8c12ba8
 
 /* WDOGINTCLR */
 #define STARFIVE_WDT_INTCLR			0x1
@@ -89,8 +112,11 @@ struct starfive_wdt_variant {
 	unsigned int int_clr;		/* Watchdog Interrupt Clear Register */
 	unsigned int unlock;		/* Watchdog Lock Register */
 	unsigned int int_status;	/* Watchdog Interrupt Status Register */
+	unsigned int restart;		/* Watchdog Counter Restart Register */
 
 	u32 unlock_key;
+	u32 restart_key;
+	u32 rst_mode;			/* control bits to reset on the first timeout */
 	char enrst_shift;
 	char en_shift;
 	bool intclr_check;		/*  whether need to check it before clearing interrupt */
@@ -144,6 +170,23 @@ static const struct starfive_wdt_variant starfive_wdt_jh7110_variant = {
 	.double_timeout = true,
 };
 
+/* Register layout and configuration for the JHB100 */
+static const struct starfive_wdt_variant starfive_wdt_jhb100_variant = {
+	.control = STARFIVE_WDT_JHB100_CONTROL,
+	.load = STARFIVE_WDT_JHB100_LOAD,
+	.enable = STARFIVE_WDT_JHB100_CONTROL,
+	.value = STARFIVE_WDT_JHB100_VALUE,
+	.unlock = STARFIVE_WDT_JHB100_LOCK,
+	.unlock_key = STARFIVE_WDT_JHB100_UNLOCK_KEY,
+	.restart = STARFIVE_WDT_JHB100_RESTART,
+	.restart_key = STARFIVE_WDT_JHB100_RESTART_KEY,
+	.rst_mode = STARFIVE_WDT_JHB100_RST_MODE,
+	.enrst_shift = STARFIVE_WDT_JHB100_RST_EN_SHIFT,
+	.en_shift = STARFIVE_WDT_EN_SHIFT,
+	.intclr_check = false,
+	.double_timeout = false,
+};
+
 static int starfive_wdt_enable_clock(struct starfive_wdt *wdt)
 {
 	int ret;
@@ -225,6 +268,7 @@ static void starfive_wdt_enable_reset(struct starfive_wdt *wdt)
 
 	val = readl(wdt->base + wdt->variant->control);
 	val |= STARFIVE_WDT_RESET_EN << wdt->variant->enrst_shift;
+	val |= wdt->variant->rst_mode;
 	writel(val, wdt->base + wdt->variant->control);
 }
 
@@ -255,7 +299,12 @@ static int starfive_wdt_int_clr(struct starfive_wdt *wdt)
 			return dev_err_probe(wdt->wdd.parent, ret,
 					     "watchdog is not ready to clear interrupt.\n");
 	}
-	writel(STARFIVE_WDT_INTCLR, wdt->base + wdt->variant->int_clr);
+
+	/* JHB100 restarts the counter by writing the restart key */
+	if (wdt->variant->restart)
+		writel(wdt->variant->restart_key, wdt->base + wdt->variant->restart);
+	else
+		writel(STARFIVE_WDT_INTCLR, wdt->base + wdt->variant->int_clr);
 
 	return 0;
 }
@@ -606,6 +655,7 @@ static const struct dev_pm_ops starfive_wdt_pm_ops = {
 static const struct of_device_id starfive_wdt_match[] = {
 	{ .compatible = "starfive,jh7100-wdt", .data = &starfive_wdt_jh7100_variant },
 	{ .compatible = "starfive,jh7110-wdt", .data = &starfive_wdt_jh7110_variant },
+	{ .compatible = "starfive,jhb100-wdt", .data = &starfive_wdt_jhb100_variant },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, starfive_wdt_match);
@@ -623,5 +673,6 @@ module_platform_driver(starfive_wdt_driver);
 
 MODULE_AUTHOR("Xingyu Wu <xingyu.wu@starfivetech.com>");
 MODULE_AUTHOR("Samin Guo <samin.guo@starfivetech.com>");
+MODULE_AUTHOR("Henry Qin <henry.qin@starfivetech.com>");
 MODULE_DESCRIPTION("StarFive Watchdog Device Driver");
 MODULE_LICENSE("GPL");
-- 
2.43.0


  parent reply	other threads:[~2026-12-04 13:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 13:53 [PATCH 0/3] watchdog: starfive: Add jhb100 support Henry Qin
2026-12-04 13:53 ` [PATCH 1/3] dt-bindings: watchdog: starfive,jh7100-wdt: Remove jh8100 Henry Qin
2026-12-04 13:53 ` [PATCH 2/3] dt-bindings: watchdog: starfive,jh7100-wdt: Add jhb100 support Henry Qin
2026-12-04 13:53 ` Henry Qin [this message]
2026-12-04 14:35   ` [PATCH 3/3] watchdog: starfive: " sashiko-bot
2026-12-04 18:55 ` [PATCH 0/3] " Guenter Roeck

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=20261204135336.632-4-henry.qin@starfivetech.com \
    --to=henry.qin@starfivetech.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=robh@kernel.org \
    --cc=wim@linux-watchdog.org \
    --cc=xingyu.wu@starfivetech.com \
    --cc=ziv.xu@starfivetech.com \
    /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