* [PATCH v2 0/2] watchdog: add Renesas Window Watchdog support
@ 2025-10-14 11:29 Wolfram Sang
  2025-10-14 11:29 ` [PATCH v2 1/2] dt-bindings: watchdog: Add Renesas WWDT Wolfram Sang
  2025-10-14 11:29 ` [PATCH v2 2/2] watchdog: renesas_wwdt: add driver Wolfram Sang
  0 siblings, 2 replies; 8+ messages in thread
From: Wolfram Sang @ 2025-10-14 11:29 UTC (permalink / raw)
  To: linux-renesas-soc
  Cc: Wolfram Sang, Conor Dooley, devicetree, Geert Uytterhoeven,
	Guenter Roeck, Krzysztof Kozlowski, linux-watchdog, Magnus Damm,
	Rob Herring, Wim Van Sebroeck
This Window Watchdog is a little peculiar because it can only be setup
once but we cannot find out if this write already happened. So,
configuration is delegated to the firmware/bootloader and the driver
will adapt to whatever is configured. The driver handles all bits
described in the datasheets. This is really all there is.
Tested on a SparrowHawk board (Renesas R-Car V4H). Based on v6.18-rc1
and build bot is already happy. Passes also binding checks and dtb
checks here.
Big picture change since v1 (details mentioned per patch):
* support not only V4H but all Gen3/4 SoCs having this WWDT
Looking forward to comments!
Wolfram Sang (2):
  dt-bindings: watchdog: Add Renesas WWDT
  watchdog: renesas_wwdt: add driver
 .../watchdog/renesas,rcar-gen3-wwdt.yaml      | 114 ++++++++++++
 drivers/watchdog/Kconfig                      |   8 +
 drivers/watchdog/Makefile                     |   1 +
 drivers/watchdog/renesas_wwdt.c               | 163 ++++++++++++++++++
 4 files changed, 286 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/renesas,rcar-gen3-wwdt.yaml
 create mode 100644 drivers/watchdog/renesas_wwdt.c
-- 
2.47.2
^ permalink raw reply	[flat|nested] 8+ messages in thread
* [PATCH v2 1/2] dt-bindings: watchdog: Add Renesas WWDT
  2025-10-14 11:29 [PATCH v2 0/2] watchdog: add Renesas Window Watchdog support Wolfram Sang
@ 2025-10-14 11:29 ` Wolfram Sang
  2025-10-17 20:34   ` Rob Herring (Arm)
  2025-10-14 11:29 ` [PATCH v2 2/2] watchdog: renesas_wwdt: add driver Wolfram Sang
  1 sibling, 1 reply; 8+ messages in thread
From: Wolfram Sang @ 2025-10-14 11:29 UTC (permalink / raw)
  To: linux-renesas-soc
  Cc: Wolfram Sang, Wim Van Sebroeck, Guenter Roeck, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Geert Uytterhoeven,
	Magnus Damm, linux-watchdog, devicetree
Describe the Window Watchdog Timer found on Renesas R-Car SoCs from late
Gen3 onwards.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Note: Despite the name, V3U is considered to be a Gen4 SoC.
Changes since v1:
* support not only V4H but all Gen3/4 SoCs having this WWDT
* handle the two-resets exception for V3U and S4
* switch order of clocks, so it is the same as for the resets
  (for resets, "cnt" is always present and "bus" is optional)
* rename the file to match the base compatible
* require interrupts and resets
* drop unneeded label from the example
 .../watchdog/renesas,rcar-gen3-wwdt.yaml      | 114 ++++++++++++++++++
 1 file changed, 114 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/renesas,rcar-gen3-wwdt.yaml
diff --git a/Documentation/devicetree/bindings/watchdog/renesas,rcar-gen3-wwdt.yaml b/Documentation/devicetree/bindings/watchdog/renesas,rcar-gen3-wwdt.yaml
new file mode 100644
index 000000000000..ffafe9a6d3f5
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/renesas,rcar-gen3-wwdt.yaml
@@ -0,0 +1,114 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/watchdog/renesas,rcar-gen3-wwdt.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Renesas Window Watchdog Timer (WWDT) Controller
+
+maintainers:
+  - Wolfram Sang <wsa+renesas@sang-engineering.com>
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - renesas,r8a77970-wwdt  # R-Car V3M
+              - renesas,r8a77980-wwdt  # R-Car V3H
+          - const: renesas,rcar-gen3-wwdt
+
+      - items:
+          - enum:
+              - renesas,r8a779a0-wwdt  # R-Car V3U
+              - renesas,r8a779f0-wwdt  # R-Car S4
+              - renesas,r8a779g0-wwdt  # R-Car V4H
+              - renesas,r8a779h0-wwdt  # R-Car V4M
+          - const: renesas,rcar-gen4-wwdt
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    items:
+      - description: Pretimeout, 75% of overflow reached
+      - description: Error occurred
+
+  interrupt-names:
+    items:
+      - const: pretimeout
+      - const: error
+
+  clocks:
+    items:
+      - description: Counting clock
+      - description: Bus clock
+
+  clock-names:
+    items:
+      - const: cnt
+      - const: bus
+
+  resets:
+    minItems: 1
+    maxItems: 2
+
+  reset-names:
+    minItems: 1
+    items:
+      - const: cnt
+      - const: bus
+
+  power-domains:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+  - clocks
+  - clock-names
+  - resets
+  - reset-names
+  - power-domains
+
+allOf:
+  - $ref: watchdog.yaml#
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - renesas,r8a779a0-wwdt
+              - renesas,r8a779f0-wwdt
+    then:
+      properties:
+        resets:
+          minItems: 2
+        reset-names:
+          minItems: 2
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/r8a779g0-cpg-mssr.h>
+    #include <dt-bindings/power/r8a779g0-sysc.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    watchdog@ffc90000 {
+            compatible = "renesas,r8a779g0-wwdt",
+                         "renesas,rcar-gen4-wwdt";
+            reg = <0xffc90000 0x10>;
+            interrupts = <GIC_SPI 310 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 311 IRQ_TYPE_LEVEL_HIGH>;
+            interrupt-names = "pretimeout", "error";
+            clocks = <&cpg CPG_CORE R8A779G0_CLK_R>,
+                     <&cpg CPG_CORE R8A779G0_CLK_SASYNCRT>;
+            clock-names = "cnt", "bus";
+            power-domains = <&sysc R8A779G0_PD_ALWAYS_ON>;
+            resets = <&cpg 1200>;
+            reset-names = "cnt";
+    };
-- 
2.47.2
^ permalink raw reply related	[flat|nested] 8+ messages in thread
* [PATCH v2 2/2] watchdog: renesas_wwdt: add driver
  2025-10-14 11:29 [PATCH v2 0/2] watchdog: add Renesas Window Watchdog support Wolfram Sang
  2025-10-14 11:29 ` [PATCH v2 1/2] dt-bindings: watchdog: Add Renesas WWDT Wolfram Sang
@ 2025-10-14 11:29 ` Wolfram Sang
  2025-10-14 15:10   ` Guenter Roeck
  1 sibling, 1 reply; 8+ messages in thread
From: Wolfram Sang @ 2025-10-14 11:29 UTC (permalink / raw)
  To: linux-renesas-soc
  Cc: Wolfram Sang, Wim Van Sebroeck, Guenter Roeck, Geert Uytterhoeven,
	Magnus Damm, linux-watchdog
This driver adds support for the Renesas Window Watchdog Timer (WWDT).
Because it can only be setup once after boot and we cannot know if this
already happened in early boot stages, it is mandated that the firmware
configures the watchdog. Linux then adapts according to the given
setup. Note that this watchdog only reports an overflow to the Error
Control Module (ECM) and does not reset the SoC on its own.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Changes since v1:
* support not only V4H but all Gen3/4 SoCs having this WWDT
* update commit message and add introductory comment to explain how
  this WWDT is handled as a "read-only" device basically
* dropped pretimeout flag because this feature cannot be configured
  from userspace
* added bitfield.h to prevent build failures
* switched to "GPL" licence string
* cosmetic updates
 drivers/watchdog/Kconfig        |   8 ++
 drivers/watchdog/Makefile       |   1 +
 drivers/watchdog/renesas_wwdt.c | 163 ++++++++++++++++++++++++++++++++
 3 files changed, 172 insertions(+)
 create mode 100644 drivers/watchdog/renesas_wwdt.c
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 05008d937e40..792d0d831336 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -969,6 +969,14 @@ config RENESAS_WDT
 	  This driver adds watchdog support for the integrated watchdogs in the
 	  Renesas R-Car and other SH-Mobile SoCs (usually named RWDT or SWDT).
 
+config RENESAS_WWDT
+	tristate "Renesas Window WWDT Watchdog"
+	depends on ARCH_RENESAS || COMPILE_TEST
+	select WATCHDOG_CORE
+	help
+	  This driver adds watchdog support for a window timer found in some
+	  Renesas R-Car Gen3 and later SoCs.
+
 config RENESAS_RZAWDT
 	tristate "Renesas RZ/A WDT Watchdog"
 	depends on ARCH_RENESAS || COMPILE_TEST
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index b680e4d3c1bc..ba52099b1253 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -85,6 +85,7 @@ obj-$(CONFIG_DIGICOLOR_WATCHDOG) += digicolor_wdt.o
 obj-$(CONFIG_LPC18XX_WATCHDOG) += lpc18xx_wdt.o
 obj-$(CONFIG_BCM7038_WDT) += bcm7038_wdt.o
 obj-$(CONFIG_RENESAS_WDT) += renesas_wdt.o
+obj-$(CONFIG_RENESAS_WWDT) += renesas_wwdt.o
 obj-$(CONFIG_RENESAS_RZAWDT) += rza_wdt.o
 obj-$(CONFIG_RENESAS_RZN1WDT) += rzn1_wdt.o
 obj-$(CONFIG_RENESAS_RZG2LWDT) += rzg2l_wdt.o
diff --git a/drivers/watchdog/renesas_wwdt.c b/drivers/watchdog/renesas_wwdt.c
new file mode 100644
index 000000000000..0f56f5c7e407
--- /dev/null
+++ b/drivers/watchdog/renesas_wwdt.c
@@ -0,0 +1,163 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for the Renesas Window Watchdog Timer (WWDT)
+ *
+ * The WWDT can only be setup once after boot. Because we cannot know if this
+ * already happened in early boot stages, it is mandated that the firmware
+ * configures the watchdog. Linux then adapts according to the given setup.
+ * Note that this watchdog only reports an overflow to the Error Control Module.
+ */
+
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+
+#define WDTA0WDTE	0x00
+#define WDTA0RUN	BIT(7)
+#define WDTA0_KEY	0x2c
+
+#define WDTA0MD		0x0c
+#define WDTA0OVF(x)	FIELD_GET(GENMASK(6, 4), x)
+#define WDTA0WIE	BIT(3)
+#define WDTA0ERM	BIT(2)
+#define WDTA0WS(x)	FIELD_GET(GENMASK(1, 0), x)
+
+struct wwdt_priv {
+	void __iomem *base;
+	struct watchdog_device wdev;
+};
+
+static int wwdt_start(struct watchdog_device *wdev)
+{
+	struct wwdt_priv *priv = watchdog_get_drvdata(wdev);
+
+	writeb(WDTA0RUN | WDTA0_KEY, priv->base + WDTA0WDTE);
+	return 0;
+}
+
+static const struct watchdog_info wwdt_ident = {
+	.options = WDIOF_KEEPALIVEPING | WDIOF_ALARMONLY,
+	.identity = "Renesas Window Watchdog",
+};
+
+static const struct watchdog_ops wwdt_ops = {
+	.owner = THIS_MODULE,
+	.start = wwdt_start,
+};
+
+static irqreturn_t wwdt_error_irq(int irq, void *dev_id)
+{
+	struct device *dev = dev_id;
+
+	dev_warn(dev, "Watchdog timed out\n");
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t wwdt_pretimeout_irq(int irq, void *dev_id)
+{
+	struct watchdog_device *wdev = dev_id;
+
+	watchdog_notify_pretimeout(wdev);
+	return IRQ_HANDLED;
+}
+
+static int wwdt_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct wwdt_priv *priv;
+	struct watchdog_device *wdev;
+	struct clk *clk;
+	unsigned long rate;
+	unsigned int interval, window_size;
+	int ret;
+	u8 val;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(priv->base))
+		return PTR_ERR(priv->base);
+
+	clk = devm_clk_get(dev, "cnt");
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+
+	rate = clk_get_rate(clk);
+	if (!rate)
+		return -EINVAL;
+
+	wdev = &priv->wdev;
+
+	val = readb(priv->base + WDTA0WDTE);
+	if (val & WDTA0RUN)
+		set_bit(WDOG_HW_RUNNING, &wdev->status);
+
+	val = readb(priv->base + WDTA0MD);
+	interval = 1 << (9 + WDTA0OVF(val));
+	/* size of the closed(!) window per mille */
+	window_size = 250 * (3 - WDTA0WS(val));
+
+	wdev->info = &wwdt_ident;
+	wdev->ops = &wwdt_ops;
+	wdev->parent = dev;
+	wdev->min_hw_heartbeat_ms = window_size * interval / rate;
+	wdev->max_hw_heartbeat_ms = 1000 * interval / rate;
+	wdev->timeout = DIV_ROUND_UP(wdev->max_hw_heartbeat_ms, 1000);
+
+	watchdog_set_drvdata(wdev, priv);
+	watchdog_set_nowayout(wdev, true);
+
+	if (!(val & WDTA0ERM)) {
+		ret = platform_get_irq_byname(pdev, "error");
+		if (ret < 0)
+			return ret;
+
+		ret = devm_request_threaded_irq(dev, ret, NULL, wwdt_error_irq,
+						IRQF_ONESHOT, NULL, dev);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (val & WDTA0WIE) {
+		ret = platform_get_irq_byname(pdev, "pretimeout");
+		if (ret < 0)
+			return ret;
+
+		ret = devm_request_threaded_irq(dev, ret, NULL, wwdt_pretimeout_irq,
+						IRQF_ONESHOT, NULL, wdev);
+		if (ret < 0)
+			return ret;
+	}
+
+	devm_watchdog_register_device(dev, wdev);
+
+	return 0;
+}
+
+static const struct of_device_id renesas_wwdt_ids[] = {
+	{ .compatible = "renesas,rcar-gen3-wwdt", },
+	{ .compatible = "renesas,rcar-gen4-wwdt", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, renesas_wwdt_ids);
+
+static struct platform_driver renesas_wwdt_driver = {
+	.driver = {
+		.name = "renesas_wwdt",
+		.of_match_table = renesas_wwdt_ids,
+	},
+	.probe = wwdt_probe,
+};
+module_platform_driver(renesas_wwdt_driver);
+
+MODULE_DESCRIPTION("Renesas Window Watchdog (WWDT) Driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Wolfram Sang <wsa+renesas@sang-engineering.com>");
-- 
2.47.2
^ permalink raw reply related	[flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] watchdog: renesas_wwdt: add driver
  2025-10-14 11:29 ` [PATCH v2 2/2] watchdog: renesas_wwdt: add driver Wolfram Sang
@ 2025-10-14 15:10   ` Guenter Roeck
  2025-10-14 21:19     ` Wolfram Sang
  0 siblings, 1 reply; 8+ messages in thread
From: Guenter Roeck @ 2025-10-14 15:10 UTC (permalink / raw)
  To: Wolfram Sang, linux-renesas-soc
  Cc: Wim Van Sebroeck, Geert Uytterhoeven, Magnus Damm, linux-watchdog
On 10/14/25 04:29, Wolfram Sang wrote:
> This driver adds support for the Renesas Window Watchdog Timer (WWDT).
> Because it can only be setup once after boot and we cannot know if this
> already happened in early boot stages, it is mandated that the firmware
> configures the watchdog. Linux then adapts according to the given
> setup. Note that this watchdog only reports an overflow to the Error
> Control Module (ECM) and does not reset the SoC on its own.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
> 
> Changes since v1:
> 
> * support not only V4H but all Gen3/4 SoCs having this WWDT
> * update commit message and add introductory comment to explain how
>    this WWDT is handled as a "read-only" device basically
> * dropped pretimeout flag because this feature cannot be configured
>    from userspace
> * added bitfield.h to prevent build failures
> * switched to "GPL" licence string
> * cosmetic updates
> 
>   drivers/watchdog/Kconfig        |   8 ++
>   drivers/watchdog/Makefile       |   1 +
>   drivers/watchdog/renesas_wwdt.c | 163 ++++++++++++++++++++++++++++++++
>   3 files changed, 172 insertions(+)
>   create mode 100644 drivers/watchdog/renesas_wwdt.c
> 
> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> index 05008d937e40..792d0d831336 100644
> --- a/drivers/watchdog/Kconfig
> +++ b/drivers/watchdog/Kconfig
> @@ -969,6 +969,14 @@ config RENESAS_WDT
>   	  This driver adds watchdog support for the integrated watchdogs in the
>   	  Renesas R-Car and other SH-Mobile SoCs (usually named RWDT or SWDT).
>   
> +config RENESAS_WWDT
> +	tristate "Renesas Window WWDT Watchdog"
> +	depends on ARCH_RENESAS || COMPILE_TEST
> +	select WATCHDOG_CORE
> +	help
> +	  This driver adds watchdog support for a window timer found in some
> +	  Renesas R-Car Gen3 and later SoCs.
> +
>   config RENESAS_RZAWDT
>   	tristate "Renesas RZ/A WDT Watchdog"
>   	depends on ARCH_RENESAS || COMPILE_TEST
> diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> index b680e4d3c1bc..ba52099b1253 100644
> --- a/drivers/watchdog/Makefile
> +++ b/drivers/watchdog/Makefile
> @@ -85,6 +85,7 @@ obj-$(CONFIG_DIGICOLOR_WATCHDOG) += digicolor_wdt.o
>   obj-$(CONFIG_LPC18XX_WATCHDOG) += lpc18xx_wdt.o
>   obj-$(CONFIG_BCM7038_WDT) += bcm7038_wdt.o
>   obj-$(CONFIG_RENESAS_WDT) += renesas_wdt.o
> +obj-$(CONFIG_RENESAS_WWDT) += renesas_wwdt.o
>   obj-$(CONFIG_RENESAS_RZAWDT) += rza_wdt.o
>   obj-$(CONFIG_RENESAS_RZN1WDT) += rzn1_wdt.o
>   obj-$(CONFIG_RENESAS_RZG2LWDT) += rzg2l_wdt.o
> diff --git a/drivers/watchdog/renesas_wwdt.c b/drivers/watchdog/renesas_wwdt.c
> new file mode 100644
> index 000000000000..0f56f5c7e407
> --- /dev/null
> +++ b/drivers/watchdog/renesas_wwdt.c
> @@ -0,0 +1,163 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Driver for the Renesas Window Watchdog Timer (WWDT)
> + *
> + * The WWDT can only be setup once after boot. Because we cannot know if this
> + * already happened in early boot stages, it is mandated that the firmware
> + * configures the watchdog. Linux then adapts according to the given setup.
What if it didn't happen ? Is WDTA0OVF set to a reasonable default in that case ?
> + * Note that this watchdog only reports an overflow to the Error Control Module.
Kind of unusual. Why not panic in that case, and why have the watchdog in the first
place ?
> + */
> +
> +#include <linux/bitfield.h>
> +#include <linux/clk.h>
> +#include <linux/interrupt.h>
> +#include <linux/io.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/watchdog.h>
> +
> +#define WDTA0WDTE	0x00
> +#define WDTA0RUN	BIT(7)
> +#define WDTA0_KEY	0x2c
> +
> +#define WDTA0MD		0x0c
> +#define WDTA0OVF(x)	FIELD_GET(GENMASK(6, 4), x)
> +#define WDTA0WIE	BIT(3)
> +#define WDTA0ERM	BIT(2)
> +#define WDTA0WS(x)	FIELD_GET(GENMASK(1, 0), x)
> +
> +struct wwdt_priv {
> +	void __iomem *base;
> +	struct watchdog_device wdev;
> +};
> +
> +static int wwdt_start(struct watchdog_device *wdev)
> +{
> +	struct wwdt_priv *priv = watchdog_get_drvdata(wdev);
> +
Maybe use container_of() ?
> +	writeb(WDTA0RUN | WDTA0_KEY, priv->base + WDTA0WDTE);
> +	return 0;
> +}
> +
> +static const struct watchdog_info wwdt_ident = {
> +	.options = WDIOF_KEEPALIVEPING | WDIOF_ALARMONLY,
> +	.identity = "Renesas Window Watchdog",
> +};
> +
> +static const struct watchdog_ops wwdt_ops = {
> +	.owner = THIS_MODULE,
> +	.start = wwdt_start,
> +};
> +
> +static irqreturn_t wwdt_error_irq(int irq, void *dev_id)
> +{
> +	struct device *dev = dev_id;
> +
> +	dev_warn(dev, "Watchdog timed out\n");
So the pretimeout may trigger a reboot (panic) if the pretimeout
governor is set to it, but the real watchdog just says Hi.
Does that really make sense ?
> +	return IRQ_HANDLED;
> +}
> +
> +static irqreturn_t wwdt_pretimeout_irq(int irq, void *dev_id)
> +{
> +	struct watchdog_device *wdev = dev_id;
> +
> +	watchdog_notify_pretimeout(wdev);
> +	return IRQ_HANDLED;
> +}
> +
> +static int wwdt_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct wwdt_priv *priv;
> +	struct watchdog_device *wdev;
> +	struct clk *clk;
> +	unsigned long rate;
> +	unsigned int interval, window_size;
> +	int ret;
> +	u8 val;
> +
> +	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +
> +	priv->base = devm_platform_ioremap_resource(pdev, 0);
> +	if (IS_ERR(priv->base))
> +		return PTR_ERR(priv->base);
> +
> +	clk = devm_clk_get(dev, "cnt");
> +	if (IS_ERR(clk))
> +		return PTR_ERR(clk);
> +
> +	rate = clk_get_rate(clk);
> +	if (!rate)
> +		return -EINVAL;
> +
> +	wdev = &priv->wdev;
> +
> +	val = readb(priv->base + WDTA0WDTE);
> +	if (val & WDTA0RUN)
> +		set_bit(WDOG_HW_RUNNING, &wdev->status);
> +
> +	val = readb(priv->base + WDTA0MD);
> +	interval = 1 << (9 + WDTA0OVF(val));
> +	/* size of the closed(!) window per mille */
> +	window_size = 250 * (3 - WDTA0WS(val));
> +
> +	wdev->info = &wwdt_ident;
> +	wdev->ops = &wwdt_ops;
> +	wdev->parent = dev;
> +	wdev->min_hw_heartbeat_ms = window_size * interval / rate;
> +	wdev->max_hw_heartbeat_ms = 1000 * interval / rate;
> +	wdev->timeout = DIV_ROUND_UP(wdev->max_hw_heartbeat_ms, 1000);
> +
> +	watchdog_set_drvdata(wdev, priv);
> +	watchdog_set_nowayout(wdev, true);
> +
> +	if (!(val & WDTA0ERM)) {
> +		ret = platform_get_irq_byname(pdev, "error");
> +		if (ret < 0)
> +			return ret;
> +
> +		ret = devm_request_threaded_irq(dev, ret, NULL, wwdt_error_irq,
> +						IRQF_ONESHOT, NULL, dev);
> +		if (ret < 0)
> +			return ret;
> +	}
> +
> +	if (val & WDTA0WIE) {
> +		ret = platform_get_irq_byname(pdev, "pretimeout");
> +		if (ret < 0)
> +			return ret;
> +
> +		ret = devm_request_threaded_irq(dev, ret, NULL, wwdt_pretimeout_irq,
> +						IRQF_ONESHOT, NULL, wdev);
> +		if (ret < 0)
> +			return ret;
> +	}
> +
> +	devm_watchdog_register_device(dev, wdev);
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id renesas_wwdt_ids[] = {
> +	{ .compatible = "renesas,rcar-gen3-wwdt", },
> +	{ .compatible = "renesas,rcar-gen4-wwdt", },
> +	{ /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(of, renesas_wwdt_ids);
> +
> +static struct platform_driver renesas_wwdt_driver = {
> +	.driver = {
> +		.name = "renesas_wwdt",
> +		.of_match_table = renesas_wwdt_ids,
> +	},
> +	.probe = wwdt_probe,
> +};
> +module_platform_driver(renesas_wwdt_driver);
> +
> +MODULE_DESCRIPTION("Renesas Window Watchdog (WWDT) Driver");
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Wolfram Sang <wsa+renesas@sang-engineering.com>");
^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] watchdog: renesas_wwdt: add driver
  2025-10-14 15:10   ` Guenter Roeck
@ 2025-10-14 21:19     ` Wolfram Sang
  2025-10-15 10:25       ` Guenter Roeck
  0 siblings, 1 reply; 8+ messages in thread
From: Wolfram Sang @ 2025-10-14 21:19 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-renesas-soc, Wim Van Sebroeck, Geert Uytterhoeven,
	Magnus Damm, linux-watchdog
[-- Attachment #1: Type: text/plain, Size: 1799 bytes --]
Hi Guenter,
thanks for the fast review!
> > + * The WWDT can only be setup once after boot. Because we cannot know if this
> > + * already happened in early boot stages, it is mandated that the firmware
> > + * configures the watchdog. Linux then adapts according to the given setup.
> 
> What if it didn't happen ? Is WDTA0OVF set to a reasonable default in that case ?
It will overflow pretty fast, but it will be in a working condition,
generally.
> 
> > + * Note that this watchdog only reports an overflow to the Error Control Module.
> 
> Kind of unusual. Why not panic in that case, and why have the watchdog in the first
> place ?
We have multiple WWDTs on the SoCs, namely as much as we have cores. The
idea is to utilize one per SoC. In normal configuration, the Error
Control Module (ECM) gets notified of overflows and will act
accordingly. It has more options than a reset, it can e.g. raise
dedicated pins to trigger actions. Sadly, we don't have a driver for ECM
yet upstream, but we need to start somewhere.
> > +	struct wwdt_priv *priv = watchdog_get_drvdata(wdev);
> > +
> Maybe use container_of() ?
Ok.
> > +static irqreturn_t wwdt_error_irq(int irq, void *dev_id)
> > +{
> > +	struct device *dev = dev_id;
> > +
> > +	dev_warn(dev, "Watchdog timed out\n");
> 
> So the pretimeout may trigger a reboot (panic) if the pretimeout
> governor is set to it, but the real watchdog just says Hi.
> Does that really make sense ?
It depends on how the ECM is configured. It can make sense. If someone
misconfigures, it might not make sense. But maybe we just don't use
pretimeout here because for Linux this is system-wide while the WWDT
usually has a smaller scale?
Does this make it more clear?
Happy hacking,
   Wolfram
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] watchdog: renesas_wwdt: add driver
  2025-10-14 21:19     ` Wolfram Sang
@ 2025-10-15 10:25       ` Guenter Roeck
  2025-10-16  7:44         ` Wolfram Sang
  0 siblings, 1 reply; 8+ messages in thread
From: Guenter Roeck @ 2025-10-15 10:25 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-renesas-soc, Wim Van Sebroeck, Geert Uytterhoeven,
	Magnus Damm, linux-watchdog
On 10/14/25 14:19, Wolfram Sang wrote:
> Hi Guenter,
> 
> thanks for the fast review!
> 
>>> + * The WWDT can only be setup once after boot. Because we cannot know if this
>>> + * already happened in early boot stages, it is mandated that the firmware
>>> + * configures the watchdog. Linux then adapts according to the given setup.
>>
>> What if it didn't happen ? Is WDTA0OVF set to a reasonable default in that case ?
> 
> It will overflow pretty fast, but it will be in a working condition,
> generally.
> 
>>
>>> + * Note that this watchdog only reports an overflow to the Error Control Module.
>>
>> Kind of unusual. Why not panic in that case, and why have the watchdog in the first
>> place ?
> 
> We have multiple WWDTs on the SoCs, namely as much as we have cores. The
> idea is to utilize one per SoC. In normal configuration, the Error
> Control Module (ECM) gets notified of overflows and will act
> accordingly. It has more options than a reset, it can e.g. raise
> dedicated pins to trigger actions. Sadly, we don't have a driver for ECM
> yet upstream, but we need to start somewhere.
> 
>>> +	struct wwdt_priv *priv = watchdog_get_drvdata(wdev);
>>> +
>> Maybe use container_of() ?
> 
> Ok.
> 
>>> +static irqreturn_t wwdt_error_irq(int irq, void *dev_id)
>>> +{
>>> +	struct device *dev = dev_id;
>>> +
>>> +	dev_warn(dev, "Watchdog timed out\n");
>>
>> So the pretimeout may trigger a reboot (panic) if the pretimeout
>> governor is set to it, but the real watchdog just says Hi.
>> Does that really make sense ?
> 
> It depends on how the ECM is configured. It can make sense. If someone
> misconfigures, it might not make sense. But maybe we just don't use
> pretimeout here because for Linux this is system-wide while the WWDT
> usually has a smaller scale?
> 
> Does this make it more clear?
> 
Yes. Assuming you know what you are doing,
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> Happy hacking,
> 
>     Wolfram
> 
^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] watchdog: renesas_wwdt: add driver
  2025-10-15 10:25       ` Guenter Roeck
@ 2025-10-16  7:44         ` Wolfram Sang
  0 siblings, 0 replies; 8+ messages in thread
From: Wolfram Sang @ 2025-10-16  7:44 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-renesas-soc, Wim Van Sebroeck, Geert Uytterhoeven,
	Magnus Damm, linux-watchdog
> > It depends on how the ECM is configured. It can make sense. If someone
> > misconfigures, it might not make sense. But maybe we just don't use
> > pretimeout here because for Linux this is system-wide while the WWDT
> > usually has a smaller scale?
> > 
> > Does this make it more clear?
> > 
> 
> Yes. Assuming you know what you are doing,
Hehe, famous last words... :D
> Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Thank you!
^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: watchdog: Add Renesas WWDT
  2025-10-14 11:29 ` [PATCH v2 1/2] dt-bindings: watchdog: Add Renesas WWDT Wolfram Sang
@ 2025-10-17 20:34   ` Rob Herring (Arm)
  0 siblings, 0 replies; 8+ messages in thread
From: Rob Herring (Arm) @ 2025-10-17 20:34 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Guenter Roeck, Wim Van Sebroeck, linux-watchdog,
	Krzysztof Kozlowski, Conor Dooley, devicetree, Geert Uytterhoeven,
	Magnus Damm, linux-renesas-soc
On Tue, 14 Oct 2025 13:29:53 +0200, Wolfram Sang wrote:
> Describe the Window Watchdog Timer found on Renesas R-Car SoCs from late
> Gen3 onwards.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
> 
> Note: Despite the name, V3U is considered to be a Gen4 SoC.
> 
> Changes since v1:
> 
> * support not only V4H but all Gen3/4 SoCs having this WWDT
> * handle the two-resets exception for V3U and S4
> * switch order of clocks, so it is the same as for the resets
>   (for resets, "cnt" is always present and "bus" is optional)
> * rename the file to match the base compatible
> * require interrupts and resets
> * drop unneeded label from the example
> 
>  .../watchdog/renesas,rcar-gen3-wwdt.yaml      | 114 ++++++++++++++++++
>  1 file changed, 114 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/watchdog/renesas,rcar-gen3-wwdt.yaml
> 
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
^ permalink raw reply	[flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-10-17 20:34 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-14 11:29 [PATCH v2 0/2] watchdog: add Renesas Window Watchdog support Wolfram Sang
2025-10-14 11:29 ` [PATCH v2 1/2] dt-bindings: watchdog: Add Renesas WWDT Wolfram Sang
2025-10-17 20:34   ` Rob Herring (Arm)
2025-10-14 11:29 ` [PATCH v2 2/2] watchdog: renesas_wwdt: add driver Wolfram Sang
2025-10-14 15:10   ` Guenter Roeck
2025-10-14 21:19     ` Wolfram Sang
2025-10-15 10:25       ` Guenter Roeck
2025-10-16  7:44         ` Wolfram Sang
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).