Skip to contentSkip to conversation

dt-bindings: watchdog: add Broadcom's BCM63xx watchdog

PATCH In review Rafał Miłecki 3 participants 7 messages Oct 27, 2021 – Oct 28, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 dt-bindings: watchdog: add Broadcom's BCM63xx watchdog

From: Rafał Miłecki <[email protected]>

It's a block that can be found on old MIPS devices as well as on relatively new BCM4908.

---
 .../bindings/watchdog/brcm,bcm63xx-wdt.yaml   | 50 +++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/brcm,bcm63xx-wdt.yaml
Documentation/devicetree/bindings/watchdog/brcm,bcm63xx-wdt.yaml new file +50 -0
new file mode 100644
index 000000000000..f89bdefdeb19
@@ -0,0 +1,50 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/watchdog/brcm,bcm63xx-wdt.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: BCM63xx watchdog
+
+allOf:
+  - $ref: "watchdog.yaml#"
+
+maintainers:
+  - Rafał Miłecki <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - brcm,bcm3368-wdt
+      - brcm,bcm4908-wdt
+      - brcm,bcm6328-wdt
+      - brcm,bcm6338-wdt
+      - brcm,bcm6345-wdt
+      - brcm,bcm6348-wdt
+      - brcm,bcm6358-wdt
+      - brcm,bcm6362-wdt
+      - brcm,bcm6368-wdt
+      - brcm,bcm6838-wdt
+      - brcm,bcm6848-wdt
+      - brcm,bcm6858-wdt
+      - brcm,bcm60333-wdt
+      - brcm,bcm63138-wdt
+      - brcm,bcm63148-wdt
+      - brcm,bcm63268-wdt
+      - brcm,bcm63381-wdt
+      - brcm,bcm68360-wdt
+
+  reg:
+    maxItems: 1
+
+unevaluatedProperties: false
+
+required:
+  - reg
+
+examples:
+  - |
+    watchdog@ff800400 {
+      compatible = "brcm,bcm4908-wdt";
+      reg = <0xff800400 0x3c>;
+    };
Signature · 1 line
2.31.1
#1 lore raw

PATCH 2/3 watchdog: bcm63xx_wdt: support compiling with COMPILE_TEST

From: Rafał Miłecki <[email protected]>

Most of this driver uses generic code and can be compile tested on any platform / arch. Move watchdog specific defines to a globally available header and check for BCM63XX for platform specific code.

This helps maintaining kernel / driver and will allow adding support for other platforms later.

---
 arch/mips/bcm63xx/prom.c                      |  1 +
 arch/mips/bcm63xx/setup.c                     |  1 +
 .../include/asm/mach-bcm63xx/bcm63xx_regs.h   | 22 ------------
 drivers/watchdog/Kconfig                      |  2 +-
 drivers/watchdog/bcm63xx_wdt.c                | 35 +++++++++++++++----
 include/linux/bcm63xx_wdt.h                   | 24 +++++++++++++
 6 files changed, 55 insertions(+), 30 deletions(-)
 create mode 100644 include/linux/bcm63xx_wdt.h
arch/mips/bcm63xx/prom.c +1 -0
index c3a2ea62c5c3..5e602a58a986 100644
@@ -6,6 +6,7 @@
  * Copyright (C) 2008 Maxime Bizon <[email protected]>
  */
 
+#include <linux/bcm63xx_wdt.h>
 #include <linux/init.h>
 #include <linux/memblock.h>
 #include <linux/smp.h>
arch/mips/bcm63xx/setup.c +1 -0
index d811e3e03f81..86d4ad7dc8ba 100644
@@ -6,6 +6,7 @@
  * Copyright (C) 2008 Maxime Bizon <[email protected]>
  */
 
+#include <linux/bcm63xx_wdt.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/delay.h>
arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h +0 -22
index 9ceb5e72889f..fc0272e2dec2 100644
@@ -441,28 +441,6 @@
 #define TIMER_CTL_ENABLE_MASK		(1 << 31)
 
 
-/*************************************************************************
- * _REG relative to RSET_WDT
- *************************************************************************/
-
-/* Watchdog default count register */
-#define WDT_DEFVAL_REG			0x0
-
-/* Watchdog control register */
-#define WDT_CTL_REG			0x4
-
-/* Watchdog control register constants */
-#define WDT_START_1			(0xff00)
-#define WDT_START_2			(0x00ff)
-#define WDT_STOP_1			(0xee00)
-#define WDT_STOP_2			(0x00ee)
-
-/* Watchdog reset length register */
-#define WDT_RSTLEN_REG			0x8
-
-/* Watchdog soft reset register (BCM6328 only) */
-#define WDT_SOFTRESET_REG		0xc
-
 /*************************************************************************
  * _REG relative to RSET_GPIO
  *************************************************************************/
drivers/watchdog/Kconfig +1 -1
index bf59faeb3de1..913cde027e92 100644
@@ -1711,7 +1711,7 @@ config OCTEON_WDT
 
 config BCM63XX_WDT
 	tristate "Broadcom BCM63xx hardware watchdog"
-	depends on BCM63XX
+	depends on BCM63XX || COMPILE_TEST
 	help
 	  Watchdog driver for the built in watchdog hardware in Broadcom
 	  BCM63xx SoC.
drivers/watchdog/bcm63xx_wdt.c +28 -7
index 56cc262571a5..1334e7fe77d8 100644
@@ -9,6 +9,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/bcm63xx_wdt.h>
 #include <linux/bitops.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
@@ -27,10 +28,10 @@
 #include <linux/resource.h>
 #include <linux/platform_device.h>
 
-#include <bcm63xx_cpu.h>
+#ifdef BCM63XX
 #include <bcm63xx_io.h>
-#include <bcm63xx_regs.h>
 #include <bcm63xx_timer.h>
+#endif
 
 #define PFX KBUILD_MODNAME
 
@@ -53,26 +54,40 @@ module_param(nowayout, bool, 0);
 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
 	__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
 
+static void bcm63xx_wdt_write_reg(u32 reg, u32 val)
+{
+	void __iomem *addr = bcm63xx_wdt_device.regs;
+
+	addr += reg;
+#ifdef BCM63XX
+	bcm_writel(val, addr);
+#else
+	writel(val, addr);
+#endif
+}
+
 /* HW functions */
 static void bcm63xx_wdt_hw_start(void)
 {
-	bcm_writel(0xfffffffe, bcm63xx_wdt_device.regs + WDT_DEFVAL_REG);
-	bcm_writel(WDT_START_1, bcm63xx_wdt_device.regs + WDT_CTL_REG);
-	bcm_writel(WDT_START_2, bcm63xx_wdt_device.regs + WDT_CTL_REG);
+	bcm63xx_wdt_write_reg(WDT_DEFVAL_REG, 0xfffffffe);
+	bcm63xx_wdt_write_reg(WDT_CTL_REG, WDT_START_1);
+	bcm63xx_wdt_write_reg(WDT_CTL_REG, WDT_START_2);
 }
 
 static void bcm63xx_wdt_hw_stop(void)
 {
-	bcm_writel(WDT_STOP_1, bcm63xx_wdt_device.regs + WDT_CTL_REG);
-	bcm_writel(WDT_STOP_2, bcm63xx_wdt_device.regs + WDT_CTL_REG);
+	bcm63xx_wdt_write_reg(WDT_CTL_REG, WDT_STOP_1);
+	bcm63xx_wdt_write_reg(WDT_CTL_REG, WDT_STOP_2);
 }
 
+#ifdef BCM63XX
 static void bcm63xx_wdt_isr(void *data)
 {
 	struct pt_regs *regs = get_irq_regs();
 
 	die(PFX " fire", regs);
 }
+#endif
 
 static void bcm63xx_timer_tick(struct timer_list *unused)
 {
@@ -255,11 +270,13 @@ static int bcm63xx_wdt_probe(struct platform_device *pdev)
 		return -ENXIO;
 	}
 
+#ifdef BCM63XX
 	ret = bcm63xx_timer_register(TIMER_WDT_ID, bcm63xx_wdt_isr, NULL);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to register wdt timer isr\n");
 		return ret;
 	}
+#endif
 
 	if (bcm63xx_wdt_settimeout(wdt_time)) {
 		bcm63xx_wdt_settimeout(WDT_DEFAULT_TIME);
@@ -280,7 +297,9 @@ static int bcm63xx_wdt_probe(struct platform_device *pdev)
 	return 0;
 
 unregister_timer:
+#ifdef BCM63XX
 	bcm63xx_timer_unregister(TIMER_WDT_ID);
+#endif
 	return ret;
 }
 
@@ -290,7 +309,9 @@ static int bcm63xx_wdt_remove(struct platform_device *pdev)
 		bcm63xx_wdt_pause();
 
 	misc_deregister(&bcm63xx_wdt_miscdev);
+#ifdef BCM63XX
 	bcm63xx_timer_unregister(TIMER_WDT_ID);
+#endif
 	return 0;
 }
 
include/linux/bcm63xx_wdt.h new file +24 -0
new file mode 100644
index 000000000000..a33d23237b32
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __BCM63XX_WDT_H
+#define __BCM63XX_WDT_H
+
+/* Watchdog default count register */
+#define WDT_DEFVAL_REG			0x0
+
+/* Watchdog control register */
+#define WDT_CTL_REG			0x4
+
+/* Watchdog control register constants */
+#define WDT_START_1			(0xff00)
+#define WDT_START_2			(0x00ff)
+#define WDT_STOP_1			(0xee00)
+#define WDT_STOP_2			(0x00ee)
+
+/* Watchdog reset length register */
+#define WDT_RSTLEN_REG			0x8
+
+/* Watchdog soft reset register (BCM6328 only) */
+#define WDT_SOFTRESET_REG		0xc
+
+#endif /* __BCM63XX_WDT_H */
Signature · 1 line
2.31.1
#2 lore raw

PATCH 3/3 watchdog: bcm63xx_wdt: support BCM4908

In reply to Rafał Miłecki

From: Rafał Miłecki <[email protected]>

So far bcm63xx_wdt included support for Broadcom's watchdog block of old MIPS devices only. It was also a fully platform (non-DT) driver.

The same block was recently found on BCM4908 with just a slightly different registers layout. Extend this driver to support OF and add support for per-chipset registers offsets.

---
 drivers/watchdog/Kconfig       |  2 +-
 drivers/watchdog/bcm63xx_wdt.c | 63 ++++++++++++++++++++++++++++++----
 2 files changed, 57 insertions(+), 8 deletions(-)
drivers/watchdog/Kconfig +1 -1
index 913cde027e92..58a2474cd929 100644
@@ -1711,7 +1711,7 @@ config OCTEON_WDT
 
 config BCM63XX_WDT
 	tristate "Broadcom BCM63xx hardware watchdog"
-	depends on BCM63XX || COMPILE_TEST
+	depends on ARCH_BCM4908 || BCM63XX || COMPILE_TEST
 	help
 	  Watchdog driver for the built in watchdog hardware in Broadcom
 	  BCM63xx SoC.
drivers/watchdog/bcm63xx_wdt.c +56 -7

116 lines not on this page · raw message

Signature · 1 line
2.31.1
maintainer
#3 lore raw

Re: [PATCH 3/3] watchdog: bcm63xx_wdt: support BCM4908

Quoted 10 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

So far bcm63xx_wdt included support for Broadcom's watchdog block of old MIPS devices only. It was also a fully platform (non-DT) driver.

The same block was recently found on BCM4908 with just a slightly different registers layout. Extend this driver to support OF and add support for per-chipset registers offsets.

Please convert the driver to use the watchdog subsystem first. Also, when doing so, please explain why you don't use the bcm7038 driver instead, since it serves the same hardware interface and already supports the watchdog core.

Guenter

#4 lore raw

Re: [PATCH 3/3] watchdog: bcm63xx_wdt: support BCM4908

Quoted 10 lines · Guenter Roeck
Quoted 9 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

So far bcm63xx_wdt included support for Broadcom's watchdog block of old MIPS devices only. It was also a fully platform (non-DT) driver.

The same block was recently found on BCM4908 with just a slightly different registers layout. Extend this driver to support OF and add support for per-chipset registers offsets.

Quoted 6 lines
Quoted 1 line

Please convert the driver to use the watchdog subsystem first. Also, when doing so, please explain why you don't use the bcm7038 driver instead, since it serves the same hardware interface and already supports the watchdog core.

This is too ugly unfortunately so yes let us use bcm7038_wdt.c and let me know if you need help with converting arch/mips/bcm63xx to use the bcm7038_wdt.c

Signature · 1 line
Florian
#5 lore raw
In reply to Rafał Miłecki
Quoted 42 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

It's a block that can be found on old MIPS devices as well as on relatively new BCM4908.

---
 .../bindings/watchdog/brcm,bcm63xx-wdt.yaml   | 50 +++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/brcm,bcm63xx-wdt.yaml
Documentation/devicetree/bindings/watchdog/brcm,bcm63xx-wdt.yaml new file +25 -0
new file mode 100644
index 000000000000..f89bdefdeb19
@@ -0,0 +1,50 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/watchdog/brcm,bcm63xx-wdt.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: BCM63xx watchdog
+
+allOf:
+  - $ref: "watchdog.yaml#"
+
+maintainers:
+  - Rafał Miłecki <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - brcm,bcm3368-wdt
+      - brcm,bcm4908-wdt
+      - brcm,bcm6328-wdt
+      - brcm,bcm6338-wdt
+      - brcm,bcm6345-wdt
+      - brcm,bcm6348-wdt
+      - brcm,bcm6358-wdt
+      - brcm,bcm6362-wdt

Documentation/devicetree/bindings/watchdog/brcm,bcm63xx-wdt.yaml line 35

Quoted 10 lines
Documentation/devicetree/bindings/watchdog/brcm,bcm63xx-wdt.yaml new file +10 -0
+      - brcm,bcm6368-wdt
+      - brcm,bcm6838-wdt
+      - brcm,bcm6848-wdt
+      - brcm,bcm6858-wdt
+      - brcm,bcm60333-wdt
+      - brcm,bcm63138-wdt
+      - brcm,bcm63148-wdt
+      - brcm,bcm63268-wdt
+      - brcm,bcm63381-wdt
+      - brcm,bcm68360-wdt

That's a lot of compatible strings for a piece of hardware that has not really change from the venerable BCM6345 days. I believe if you use only "brcm,bcm6345-wdt" we ought to have everything covered. Similar to the bcm63xx-uart binding.

Signature · 1 line
Florian