Devicetree
 help / color / mirror / Atom feed
* [PATCH 0/4] watchdog: histb: Add HiSilicon STB watchdog driver
@ 2026-11-22  6:55 David Yang
  2026-11-22  6:55 ` [PATCH 1/4] dt-bindings: watchdog: Add HiSilicon STB watchdog binding David Yang
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: David Yang @ 2026-11-22  6:55 UTC (permalink / raw)
  To: linux-watchdog
  Cc: David Yang, Wim Van Sebroeck, Guenter Roeck, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Wei Xu, devicetree,
	linux-kernel, linux-arm-kernel

The watchdog integrated on HiSilicon STB SoCs reuses the register layout
of sp805, but deviates from the standard sp805 in several ways that make
the existing sp805 driver unusable on these SoCs. Add a dedicated
platform driver for this controller.

David Yang (4):
  dt-bindings: watchdog: Add HiSilicon STB watchdog binding
  watchdog: histb: Add HiSilicon STB watchdog driver
  arm64: dts: hisilicon: hi3798cv200: Add watchdog node
  MAINTAINERS: Add HiSilicon STB drivers entry

 .../watchdog/hisilicon,histb-wdt.yaml         |  54 ++++
 MAINTAINERS                                   |   7 +
 .../arm64/boot/dts/hisilicon/hi3798cv200.dtsi |   8 +
 drivers/watchdog/Kconfig                      |   8 +
 drivers/watchdog/Makefile                     |   1 +
 drivers/watchdog/histb_wdt.c                  | 287 ++++++++++++++++++
 6 files changed, 365 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/hisilicon,histb-wdt.yaml
 create mode 100644 drivers/watchdog/histb_wdt.c

-- 
2.53.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] dt-bindings: watchdog: Add HiSilicon STB watchdog binding
  2026-11-22  6:55 [PATCH 0/4] watchdog: histb: Add HiSilicon STB watchdog driver David Yang
@ 2026-11-22  6:55 ` David Yang
  2026-11-22  7:03   ` sashiko-bot
  2026-11-22  6:55 ` [PATCH 2/4] watchdog: histb: Add HiSilicon STB watchdog driver David Yang
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: David Yang @ 2026-11-22  6:55 UTC (permalink / raw)
  To: linux-watchdog
  Cc: David Yang, Wim Van Sebroeck, Guenter Roeck, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Wei Xu, devicetree,
	linux-kernel, linux-arm-kernel

Add Device Tree binding schema for the watchdog controller found on
HiSilicon STB SoCs.

While sharing the register layout of ARM PrimeCell SP805, this block
does not implement PrimeCell ID registers and has non-standard reload
and lock semantics, requiring a dedicated platform driver binding.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 .../watchdog/hisilicon,histb-wdt.yaml         | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/hisilicon,histb-wdt.yaml

diff --git a/Documentation/devicetree/bindings/watchdog/hisilicon,histb-wdt.yaml b/Documentation/devicetree/bindings/watchdog/hisilicon,histb-wdt.yaml
new file mode 100644
index 000000000000..c0a8ccdb482a
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/hisilicon,histb-wdt.yaml
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/watchdog/hisilicon,histb-wdt.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: HiSilicon STB SoC Watchdog
+
+maintainers:
+  - David Yang <mmyangfl@gmail.com>
+
+description:
+  HiSilicon STB SoCs (Hi3716, Hi3798, Hi3798, etc) integrate a watchdog device,
+  which triggers an interrupt after a configurable time period. If that
+  interrupt has not been serviced when the next interrupt would be triggered,
+  the reset signal is asserted.
+
+allOf:
+  - $ref: watchdog.yaml#
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - hisilicon,hi3798cv200-wdt
+      - const: hisilicon,histb-wdt
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  clock-frequency: true
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    watchdog@8a2c000 {
+        compatible = "hisilicon,hi3798cv200-wdt", "hisilicon,histb-wdt";
+        reg = <0x8a2c000 0x1000>;
+        interrupts = <GIC_SPI 29 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&crg 0>;
+    };
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] watchdog: histb: Add HiSilicon STB watchdog driver
  2026-11-22  6:55 [PATCH 0/4] watchdog: histb: Add HiSilicon STB watchdog driver David Yang
  2026-11-22  6:55 ` [PATCH 1/4] dt-bindings: watchdog: Add HiSilicon STB watchdog binding David Yang
@ 2026-11-22  6:55 ` David Yang
  2026-11-22  7:18   ` sashiko-bot
  2026-11-22  6:55 ` [PATCH 3/4] arm64: dts: hisilicon: hi3798cv200: Add watchdog node David Yang
  2026-11-22  6:55 ` [PATCH 4/4] MAINTAINERS: Add HiSilicon STB drivers entry David Yang
  3 siblings, 1 reply; 7+ messages in thread
From: David Yang @ 2026-11-22  6:55 UTC (permalink / raw)
  To: linux-watchdog
  Cc: David Yang, Wim Van Sebroeck, Guenter Roeck, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Wei Xu, devicetree,
	linux-kernel, linux-arm-kernel

The watchdog controller integrated on HiSilicon STB SoCs shares register
offsets with the ARM PrimeCell SP805, but differs in several critical
behaviors. Add a dedicated platform driver to handle these SoC-specific
semantics natively without regressing generic SP805 users.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/watchdog/Kconfig     |   8 +
 drivers/watchdog/Makefile    |   1 +
 drivers/watchdog/histb_wdt.c | 287 +++++++++++++++++++++++++++++++++++
 3 files changed, 296 insertions(+)
 create mode 100644 drivers/watchdog/histb_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index f7d0a0c2c0ef..d3421bb76326 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -1183,6 +1183,14 @@ config SUNPLUS_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called sunplus_wdt.
 
+config HISTB_WATCHDOG
+	tristate "HiSilicon STB Watchdog"
+	depends on (ARCH_HISI || COMPILE_TEST) && OF
+	select WATCHDOG_CORE
+	help
+	  Say Y here to include support for the watchdog timer in HiSilicon STB
+	  SoCs.
+
 # X86 (i386 + ia64 + x86_64) Architecture
 
 config ACQUIRE_WDT
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 9ac406677aba..d2455e54ab23 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -106,6 +106,7 @@ obj-$(CONFIG_SUNPLUS_WATCHDOG) += sunplus_wdt.o
 obj-$(CONFIG_MARVELL_GTI_WDT) += marvell_gti_wdt.o
 obj-$(CONFIG_GUNYAH_WATCHDOG) += gunyah_wdt.o
 obj-$(CONFIG_MA35D1_WDT) += ma35d1_wdt.o
+obj-$(CONFIG_HISTB_WATCHDOG) += histb_wdt.o
 
 # X86 (i386 + ia64 + x86_64) Architecture
 obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
diff --git a/drivers/watchdog/histb_wdt.c b/drivers/watchdog/histb_wdt.c
new file mode 100644
index 000000000000..1961981f1e5d
--- /dev/null
+++ b/drivers/watchdog/histb_wdt.c
@@ -0,0 +1,287 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+/*
+ * HiSilicon STB Watchdog Driver
+ *
+ * The watchdog controller integrated on HiSilicon STB SoCs shares register
+ * offsets with the ARM PrimeCell SP805, but differs in several critical
+ * hardware behaviors:
+ *   - The ID registers at 0xfe0..0xffc are unimplemented and read zero,
+ *     requiring a platform device driver rather than AMBA probe;
+ *   - Writing WDTLOCK freezes the counter instead of only blocking register
+ *     writes, so the block must remain unlocked while running;
+ *   - Writing WDTLOAD never reloads the running counter; only WDTINTCLR does;
+ *   - Writing WDTLOAD with 0 results in a counter starting at 0xffffffff,
+ *     resetting after 2*178.6s (~6min) at 24 MHz;
+ *   - The counter only advances while unlocked and INT_ENABLE is set.
+ *
+ * Copyright (c) 2026 David Yang <mmyangfl@gmail.com>
+ */
+
+#include <linux/bitops.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/kernel.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm.h>
+#include <linux/spinlock.h>
+#include <linux/watchdog.h>
+
+#define HISTB_WDT_LOAD			0x000
+#define HISTB_WDT_VALUE			0x004
+#define HISTB_WDT_CONTROL		0x008
+#define  HISTB_WDT_RESET_ENABLE			BIT(1)
+#define  HISTB_WDT_INT_ENABLE			BIT(0)
+#define HISTB_WDT_INTCLR		0x00c
+#define HISTB_WDT_RIS			0x010
+#define HISTB_WDT_MIS			0x014
+#define  HISTB_WDT_INT_MASK			BIT(0)
+#define HISTB_WDT_LOCK			0xc00
+#define  HISTB_WDT_UNLOCK_KEY			0x1acce551
+#define  HISTB_WDT_LOCK_KEY			0x00000001
+
+#define MHz 1000000
+
+#define HISTB_WDT_DEFAULT_TIMEOUT	60
+
+struct histb_wdt {
+	struct watchdog_device wdd;
+
+	void __iomem *base;
+	struct clk *clk;
+	spinlock_t lock;
+
+	u32 rate;
+	u32 load_val;
+};
+
+static void histb_wdt_arm(struct histb_wdt *wdt, u32 load)
+{
+	void __iomem *base = wdt->base;
+
+	spin_lock(&wdt->lock);
+	writel_relaxed(HISTB_WDT_UNLOCK_KEY, base + HISTB_WDT_LOCK);
+	writel_relaxed(0, base + HISTB_WDT_CONTROL);
+	writel_relaxed(HISTB_WDT_INT_MASK, base + HISTB_WDT_INTCLR);
+	writel_relaxed(load, base + HISTB_WDT_LOAD);
+	writel_relaxed(HISTB_WDT_INT_ENABLE | HISTB_WDT_RESET_ENABLE,
+		       base + HISTB_WDT_CONTROL);
+	readl_relaxed(base + HISTB_WDT_LOCK);
+	spin_unlock(&wdt->lock);
+}
+
+static int histb_wdt_start(struct watchdog_device *wdd)
+{
+	struct histb_wdt *wdt = watchdog_get_drvdata(wdd);
+	int res;
+
+	res = clk_enable(wdt->clk);
+	if (res)
+		return res;
+
+	histb_wdt_arm(wdt, wdt->load_val);
+
+	return 0;
+}
+
+static int histb_wdt_stop(struct watchdog_device *wdd)
+{
+	struct histb_wdt *wdt = watchdog_get_drvdata(wdd);
+	void __iomem *base = wdt->base;
+
+	spin_lock(&wdt->lock);
+	writel_relaxed(HISTB_WDT_UNLOCK_KEY, base + HISTB_WDT_LOCK);
+	writel_relaxed(0, base + HISTB_WDT_CONTROL);
+	writel_relaxed(HISTB_WDT_LOCK_KEY, base + HISTB_WDT_LOCK);
+	readl_relaxed(base + HISTB_WDT_LOCK);
+	spin_unlock(&wdt->lock);
+
+	clk_disable(wdt->clk);
+
+	return 0;
+}
+
+static int histb_wdt_ping(struct watchdog_device *wdd)
+{
+	struct histb_wdt *wdt = watchdog_get_drvdata(wdd);
+	void __iomem *base = wdt->base;
+
+	spin_lock(&wdt->lock);
+	writel_relaxed(HISTB_WDT_INT_MASK, base + HISTB_WDT_INTCLR);
+	writel_relaxed(wdt->load_val, base + HISTB_WDT_LOAD);
+	readl_relaxed(base + HISTB_WDT_LOCK);
+	spin_unlock(&wdt->lock);
+
+	return 0;
+}
+
+static int
+histb_wdt_set_timeout(struct watchdog_device *wdd, unsigned int timeout)
+{
+	struct histb_wdt *wdt = watchdog_get_drvdata(wdd);
+	u64 load;
+
+	/*
+	 * Counter decrements twice: interrupt at underflow 1, reset at
+	 * underflow 2 if unclaimed. Timeout is two windows.
+	 */
+	load = div_u64((u64)wdt->rate * timeout, 2) - 1;
+	load = clamp_val(load, 1, 0xffffffff);
+
+	wdt->load_val = load;
+	wdd->timeout = div_u64(((u64)load + 1) * 2 + (wdt->rate / 2),
+			       wdt->rate);
+
+	if (watchdog_active(wdd))
+		histb_wdt_arm(wdt, wdt->load_val);
+
+	return 0;
+}
+
+static unsigned int histb_wdt_get_timeleft(struct watchdog_device *wdd)
+{
+	struct histb_wdt *wdt = watchdog_get_drvdata(wdd);
+	u64 value;
+
+	spin_lock(&wdt->lock);
+	value = readl_relaxed(wdt->base + HISTB_WDT_VALUE);
+	if (!(readl_relaxed(wdt->base + HISTB_WDT_RIS) & HISTB_WDT_INT_MASK))
+		value += (u64)wdt->load_val + 1;
+	spin_unlock(&wdt->lock);
+
+	return div_u64(value, wdt->rate);
+}
+
+static int
+histb_wdt_restart(struct watchdog_device *wdd, unsigned long mode, void *cmd)
+{
+	struct histb_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);
+	histb_wdt_arm(wdt, 1);
+
+	mdelay(1);
+
+	return 0;
+}
+
+static const struct watchdog_info histb_wdt_info = {
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+	.identity = "HiSilicon STB Watchdog",
+};
+
+static const struct watchdog_ops histb_wdt_ops = {
+	.owner = THIS_MODULE,
+	.start = histb_wdt_start,
+	.stop = histb_wdt_stop,
+	.ping = histb_wdt_ping,
+	.set_timeout = histb_wdt_set_timeout,
+	.get_timeleft = histb_wdt_get_timeleft,
+	.restart = histb_wdt_restart,
+};
+
+static int histb_wdt_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct histb_wdt *wdt;
+	int res;
+
+	wdt = devm_kzalloc_obj(dev, *wdt);
+	if (!wdt)
+		return -ENOMEM;
+
+	wdt->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(wdt->base))
+		return PTR_ERR(wdt->base);
+
+	/*
+	 * Keep the clock prepared for the lifetime of the driver:
+	 * .restart() runs in atomic context and may only call clk_enable().
+	 */
+	wdt->clk = devm_clk_get_optional_prepared(dev, NULL);
+	if (IS_ERR(wdt->clk))
+		return dev_err_probe(dev, PTR_ERR(wdt->clk),
+				     "Failed to get clock\n");
+
+	if (wdt->clk)
+		wdt->rate = clk_get_rate(wdt->clk);
+	if (!wdt->rate)
+		device_property_read_u32(dev, "clock-frequency", &wdt->rate);
+	if (!wdt->rate)
+		/* 24 MHz crystal clock default on HiSTB */
+		wdt->rate = 24 * MHz;
+
+	spin_lock_init(&wdt->lock);
+
+	wdt->wdd.info = &histb_wdt_info;
+	wdt->wdd.ops = &histb_wdt_ops;
+	wdt->wdd.parent = dev;
+	wdt->wdd.min_timeout = 1;
+	wdt->wdd.max_timeout = div_u64(((u64)U32_MAX + 1) * 2, wdt->rate);
+	wdt->wdd.timeout = HISTB_WDT_DEFAULT_TIMEOUT;
+
+	watchdog_set_drvdata(&wdt->wdd, wdt);
+	watchdog_init_timeout(&wdt->wdd, 0, dev);
+	histb_wdt_set_timeout(&wdt->wdd, wdt->wdd.timeout);
+
+	watchdog_stop_on_reboot(&wdt->wdd);
+	platform_set_drvdata(pdev, wdt);
+
+	res = devm_watchdog_register_device(dev, &wdt->wdd);
+	if (res)
+		return dev_err_probe(dev, res,
+				     "Failed to register watchdog device\n");
+
+	return 0;
+}
+
+static int __maybe_unused histb_wdt_suspend(struct device *dev)
+{
+	struct histb_wdt *wdt = dev_get_drvdata(dev);
+
+	if (watchdog_active(&wdt->wdd))
+		histb_wdt_stop(&wdt->wdd);
+
+	return 0;
+}
+
+static int __maybe_unused histb_wdt_resume(struct device *dev)
+{
+	struct histb_wdt *wdt = dev_get_drvdata(dev);
+
+	if (watchdog_active(&wdt->wdd))
+		histb_wdt_start(&wdt->wdd);
+
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(histb_wdt_pm_ops, histb_wdt_suspend, histb_wdt_resume);
+
+static const struct of_device_id histb_wdt_match[] = {
+	{ .compatible = "hisilicon,histb-wdt" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, histb_wdt_match);
+
+static struct platform_driver histb_wdt_driver = {
+	.probe = histb_wdt_probe,
+	.driver = {
+		.name = "histb-wdt",
+		.pm = &histb_wdt_pm_ops,
+		.of_match_table = histb_wdt_match,
+	},
+};
+module_platform_driver(histb_wdt_driver);
+
+MODULE_AUTHOR("David Yang <mmyangfl@gmail.com>");
+MODULE_DESCRIPTION("HiSilicon STB Watchdog Driver");
+MODULE_LICENSE("Dual MIT/GPL");
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] arm64: dts: hisilicon: hi3798cv200: Add watchdog node
  2026-11-22  6:55 [PATCH 0/4] watchdog: histb: Add HiSilicon STB watchdog driver David Yang
  2026-11-22  6:55 ` [PATCH 1/4] dt-bindings: watchdog: Add HiSilicon STB watchdog binding David Yang
  2026-11-22  6:55 ` [PATCH 2/4] watchdog: histb: Add HiSilicon STB watchdog driver David Yang
@ 2026-11-22  6:55 ` David Yang
  2026-11-22  6:55 ` [PATCH 4/4] MAINTAINERS: Add HiSilicon STB drivers entry David Yang
  3 siblings, 0 replies; 7+ messages in thread
From: David Yang @ 2026-11-22  6:55 UTC (permalink / raw)
  To: linux-watchdog
  Cc: David Yang, Wim Van Sebroeck, Guenter Roeck, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Wei Xu, devicetree,
	linux-kernel, linux-arm-kernel

Add the on-chip watchdog controller node to hi3798cv200.dtsi,
backed by the new hisilicon,histb-wdt platform driver.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 arch/arm64/boot/dts/hisilicon/hi3798cv200.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/arm64/boot/dts/hisilicon/hi3798cv200.dtsi b/arch/arm64/boot/dts/hisilicon/hi3798cv200.dtsi
index e5010c9d4c39..169a919bb282 100644
--- a/arch/arm64/boot/dts/hisilicon/hi3798cv200.dtsi
+++ b/arch/arm64/boot/dts/hisilicon/hi3798cv200.dtsi
@@ -254,6 +254,14 @@ range: gpio-range {
 			};
 		};
 
+		watchdog0: watchdog@8a2c000 {
+			compatible = "hisilicon,hi3798cv200-wdt", "hisilicon,histb-wdt";
+			reg = <0x8a2c000 0x1000>;
+			interrupts = <GIC_SPI 29 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&crg HISTB_OSC_CLK>;
+			status = "disabled";
+		};
+
 		uart0: serial@8b00000 {
 			compatible = "arm,pl011", "arm,primecell";
 			reg = <0x8b00000 0x1000>;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] MAINTAINERS: Add HiSilicon STB drivers entry
  2026-11-22  6:55 [PATCH 0/4] watchdog: histb: Add HiSilicon STB watchdog driver David Yang
                   ` (2 preceding siblings ...)
  2026-11-22  6:55 ` [PATCH 3/4] arm64: dts: hisilicon: hi3798cv200: Add watchdog node David Yang
@ 2026-11-22  6:55 ` David Yang
  3 siblings, 0 replies; 7+ messages in thread
From: David Yang @ 2026-11-22  6:55 UTC (permalink / raw)
  To: linux-watchdog
  Cc: David Yang, Wim Van Sebroeck, Guenter Roeck, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Wei Xu, devicetree,
	linux-kernel, linux-arm-kernel

Add a MAINTAINERS entry for the HiSilicon STB platform drivers, covering
the histb-wdt watchdog driver and the existing histb-rng hardware RNG
driver.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 2ac5128b756e..f248a04b925c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12187,6 +12187,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/mfd/hisilicon,hi6421-spmi-pmic.yaml
 F:	drivers/mfd/hi6421-spmi-pmic.c
 
+HISILICON STB DRIVERS
+M:	David Yang <mmyangfl@gmail.com>
+S:	Maintained
+F:	Documentation/devicetree/bindings/watchdog/hisilicon,histb-wdt.yaml
+F:	drivers/char/hw_random/histb-rng.c
+F:	drivers/watchdog/histb_wdt.c
+
 HISILICON TRUE RANDOM NUMBER GENERATOR V2 SUPPORT
 M:	Weili Qian <qianweili@huawei.com>
 S:	Maintained
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/4] dt-bindings: watchdog: Add HiSilicon STB watchdog binding
  2026-11-22  6:55 ` [PATCH 1/4] dt-bindings: watchdog: Add HiSilicon STB watchdog binding David Yang
@ 2026-11-22  7:03   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-22  7:03 UTC (permalink / raw)
  To: David Yang, linux-watchdog; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] dt-bindings: watchdog: redundant word binding in commit subject
- [Low] dt-bindings: watchdog: non-canonical property order in example
  node
--

commit a1622b56fb454eac20ec415b3fb13ffbe0760e8a
Author: David Yang <mmyangfl@gmail.com>

dt-bindings: watchdog: Add HiSilicon STB watchdog binding

This commit adds a Device Tree binding schema for the watchdog controller
found on HiSilicon STB SoCs.

> dt-bindings: watchdog: Add HiSilicon STB watchdog binding

[Severity: Low]
The "dt-bindings:" prefix already states that the patch adds a binding, so
"binding" at the end of the subject is redundant and can be dropped:
"dt-bindings: watchdog: Add HiSilicon STB watchdog".

> diff --git a/Documentation/devicetree/bindings/watchdog/hisilicon,histb-wdt.yaml b/Documentation/devicetree/bindings/watchdog/hisilicon,histb-wdt.yaml
> new file mode 100644
> index 0000000000000..c0a8ccdb482a4
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/watchdog/hisilicon,histb-wdt.yaml

[ ... ]

> +examples:
> +  - |
> +    #include <dt-bindings/interrupt-controller/arm-gic.h>
> +
> +    watchdog@8a2c000 {
> +        compatible = "hisilicon,hi3798cv200-wdt", "hisilicon,histb-wdt";
> +        reg = <0x8a2c000 0x1000>;
> +        interrupts = <GIC_SPI 29 IRQ_TYPE_LEVEL_HIGH>;
> +        clocks = <&crg 0>;
> +    };

[Severity: Low]
In the example node, clocks should be listed before interrupts to follow
the canonical property order used in the properties list above.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122065549.3265519-1-mmyangfl@gmail.com?part=1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/4] watchdog: histb: Add HiSilicon STB watchdog driver
  2026-11-22  6:55 ` [PATCH 2/4] watchdog: histb: Add HiSilicon STB watchdog driver David Yang
@ 2026-11-22  7:18   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-22  7:18 UTC (permalink / raw)
  To: David Yang, linux-watchdog; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] watchdog: histb: stale counter reload in histb_wdt_arm() and
  histb_wdt_ping()
- [High] watchdog: histb: unclocked MMIO reads in
  histb_wdt_get_timeleft() when stopped
- [Medium] watchdog: histb: missing watchdog_stop_on_unregister() in
  histb_wdt_probe()
- [Medium] watchdog: histb: unchecked histb_wdt_start() error in
  histb_wdt_resume()
- [Medium] watchdog: histb: deadlock and invalid wait context in
  histb_wdt_restart()
--

commit 8f21fc6b65d49db93aa95ad107c510c4d4fadce6
Author: David Yang <mmyangfl@gmail.com>

watchdog: histb: Add HiSilicon STB watchdog driver

This commit adds a platform watchdog driver for the watchdog controller
integrated on HiSilicon STB SoCs.

> diff --git a/drivers/watchdog/histb_wdt.c b/drivers/watchdog/histb_wdt.c
> new file mode 100644
> index 0000000000000..1961981f1e5d7
> --- /dev/null
> +++ b/drivers/watchdog/histb_wdt.c
> @@ -0,0 +1,287 @@
> +// SPDX-License-Identifier: GPL-2.0+ OR MIT
> +/*
> + * HiSilicon STB Watchdog Driver
> + *
> + * The watchdog controller integrated on HiSilicon STB SoCs shares register
> + * offsets with the ARM PrimeCell SP805, but differs in several critical
> + * hardware behaviors:
> + *   - The ID registers at 0xfe0..0xffc are unimplemented and read zero,
> + *     requiring a platform device driver rather than AMBA probe;
> + *   - Writing WDTLOCK freezes the counter instead of only blocking register
> + *     writes, so the block must remain unlocked while running;
> + *   - Writing WDTLOAD never reloads the running counter; only WDTINTCLR does;

[ ... ]

> +static void histb_wdt_arm(struct histb_wdt *wdt, u32 load)
> +{
> +	void __iomem *base = wdt->base;
> +
> +	spin_lock(&wdt->lock);
> +	writel_relaxed(HISTB_WDT_UNLOCK_KEY, base + HISTB_WDT_LOCK);
> +	writel_relaxed(0, base + HISTB_WDT_CONTROL);
> +	writel_relaxed(HISTB_WDT_INT_MASK, base + HISTB_WDT_INTCLR);
> +	writel_relaxed(load, base + HISTB_WDT_LOAD);
> +	writel_relaxed(HISTB_WDT_INT_ENABLE | HISTB_WDT_RESET_ENABLE,
> +		       base + HISTB_WDT_CONTROL);
> +	readl_relaxed(base + HISTB_WDT_LOCK);
> +	spin_unlock(&wdt->lock);
> +}

[ ... ]

> +static int histb_wdt_ping(struct watchdog_device *wdd)
> +{
> +	struct histb_wdt *wdt = watchdog_get_drvdata(wdd);
> +	void __iomem *base = wdt->base;
> +
> +	spin_lock(&wdt->lock);
> +	writel_relaxed(HISTB_WDT_INT_MASK, base + HISTB_WDT_INTCLR);
> +	writel_relaxed(wdt->load_val, base + HISTB_WDT_LOAD);
> +	readl_relaxed(base + HISTB_WDT_LOCK);
> +	spin_unlock(&wdt->lock);
> +
> +	return 0;
> +}

[Severity: High]
Should HISTB_WDT_LOAD be written before HISTB_WDT_INTCLR in
histb_wdt_arm() and histb_wdt_ping()?

As noted in the file header comment, writing WDTLOAD does not reload the
counter and only writing WDTINTCLR triggers the reload.  Writing
HISTB_WDT_INTCLR first reloads the counter with whatever stale value was
previously in HISTB_WDT_LOAD.  In particular, when histb_wdt_restart()
calls histb_wdt_arm(wdt, 1), the counter reloads with the old timeout (or
0xffffffff if the watchdog was never started) instead of 1, so the system
fails to reset during the 1 ms delay.

[ ... ]

> +static unsigned int histb_wdt_get_timeleft(struct watchdog_device *wdd)
> +{
> +	struct histb_wdt *wdt = watchdog_get_drvdata(wdd);
> +	u64 value;
> +
> +	spin_lock(&wdt->lock);
> +	value = readl_relaxed(wdt->base + HISTB_WDT_VALUE);
> +	if (!(readl_relaxed(wdt->base + HISTB_WDT_RIS) & HISTB_WDT_INT_MASK))
> +		value += (u64)wdt->load_val + 1;
> +	spin_unlock(&wdt->lock);
> +
> +	return div_u64(value, wdt->rate);
> +}

[Severity: High]
Can histb_wdt_get_timeleft() read HISTB_WDT_VALUE and HISTB_WDT_RIS while
wdt->clk is disabled?

wdt->clk is only prepared at probe time and is not enabled until
histb_wdt_start() is called, and histb_wdt_stop() disables it again.  The
watchdog core's timeleft sysfs attribute (and WDIOC_GETTIMELEFT ioctl)
invokes wdd->ops->get_timeleft(wdd) without checking
watchdog_active(wdd).  Reading /sys/class/watchdog/watchdogN/timeleft
while the watchdog is stopped accesses the device registers with the
clock gated, which can cause a synchronous external abort or bus hang.

> +static int
> +histb_wdt_restart(struct watchdog_device *wdd, unsigned long mode, void *cmd)
> +{
> +	struct histb_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);
> +	histb_wdt_arm(wdt, 1);
> +
> +	mdelay(1);
> +
> +	return 0;
> +}

[Severity: Medium]
Can histb_wdt_restart() deadlock on wdt->lock via histb_wdt_arm()?

Normal callers acquire wdt->lock with plain spin_lock() while local
interrupts remain enabled, whereas histb_wdt_restart() runs from the
restart notifier chain after smp_send_stop() or from emergency_restart()
in hardirq context:

CPU0                              CPU1
histb_wdt_ping()
  spin_lock(&wdt->lock)
                                  machine_restart()
                                    smp_send_stop()
  <stop IPI halts CPU0>
                                    do_kernel_restart()
                                      histb_wdt_restart()
                                        histb_wdt_arm()
                                          spin_lock(&wdt->lock)
                                            <-- spins forever

An emergency_restart() triggered from a hardirq on the same CPU while
wdt->lock is held will likewise deadlock, and taking spinlock_t from
hardirq context violates lockdep wait-context nesting on PREEMPT_RT.
Programming the registers in histb_wdt_restart() through an unlocked
helper avoids taking wdt->lock during restart.

[ ... ]

> +static int histb_wdt_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct histb_wdt *wdt;
> +	int res;
> +
> +	wdt = devm_kzalloc_obj(dev, *wdt);
> +	if (!wdt)
> +		return -ENOMEM;
> +
> +	wdt->base = devm_platform_ioremap_resource(pdev, 0);
> +	if (IS_ERR(wdt->base))
> +		return PTR_ERR(wdt->base);
> +
> +	/*
> +	 * Keep the clock prepared for the lifetime of the driver:
> +	 * .restart() runs in atomic context and may only call clk_enable().
> +	 */
> +	wdt->clk = devm_clk_get_optional_prepared(dev, NULL);

[ ... ]

> +	watchdog_stop_on_reboot(&wdt->wdd);
> +	platform_set_drvdata(pdev, wdt);
> +
> +	res = devm_watchdog_register_device(dev, &wdt->wdd);
> +	if (res)
> +		return dev_err_probe(dev, res,
> +				     "Failed to register watchdog device\n");
> +
> +	return 0;
> +}

[Severity: Medium]
Should histb_wdt_probe() also call watchdog_stop_on_unregister(&wdt->wdd)?

If the device is unbound while the watchdog is active,
devm_watchdog_register_device() unregisters the watchdog without calling
histb_wdt_stop().  That leaves the hardware counter running to reset the
system and causes the devres cleanup for devm_clk_get_optional_prepared()
to call clk_unprepare() while wdt->clk is still enabled, triggering a
WARN in clk_core_unprepare().

> +static int __maybe_unused histb_wdt_suspend(struct device *dev)
> +{
> +	struct histb_wdt *wdt = dev_get_drvdata(dev);
> +
> +	if (watchdog_active(&wdt->wdd))
> +		histb_wdt_stop(&wdt->wdd);
> +
> +	return 0;
> +}
> +
> +static int __maybe_unused histb_wdt_resume(struct device *dev)
> +{
> +	struct histb_wdt *wdt = dev_get_drvdata(dev);
> +
> +	if (watchdog_active(&wdt->wdd))
> +		histb_wdt_start(&wdt->wdd);
> +
> +	return 0;
> +}

[Severity: Medium]
Should histb_wdt_resume() propagate the return value of histb_wdt_start()?

If clk_enable() fails in histb_wdt_start() during resume, discarding the
error leaves WDOG_ACTIVE set while wdt->clk remains disabled.  Later
watchdog callbacks will then access unclocked MMIO registers and
histb_wdt_stop() will call clk_disable() on an already-disabled clock.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122065549.3265519-1-mmyangfl@gmail.com?part=2

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-22  7:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22  6:55 [PATCH 0/4] watchdog: histb: Add HiSilicon STB watchdog driver David Yang
2026-11-22  6:55 ` [PATCH 1/4] dt-bindings: watchdog: Add HiSilicon STB watchdog binding David Yang
2026-11-22  7:03   ` sashiko-bot
2026-11-22  6:55 ` [PATCH 2/4] watchdog: histb: Add HiSilicon STB watchdog driver David Yang
2026-11-22  7:18   ` sashiko-bot
2026-11-22  6:55 ` [PATCH 3/4] arm64: dts: hisilicon: hi3798cv200: Add watchdog node David Yang
2026-11-22  6:55 ` [PATCH 4/4] MAINTAINERS: Add HiSilicon STB drivers entry David Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox