watchdog: max63xx_wdt: Support a WDI pin connected to a GPIO
Subsystems (3)
v4 cover watchdog: max63xx_wdt: Support a WDI pin connected to a GPIO
This series picks up Pali's patches [1], which stopped at v3 in July 2022. Pali is on Cc.
The MAX6370 on CZ.NIC Turris 1.x routers has its SET pins connected through a CPLD, but its WDI pin is connected to a SoC GPIO. The driver currently cannot use this GPIO, despite turris1x.dts already describing it.
This series adds GPIO support to the driver and binding, and updates turris1x.dts to use the new wdi-gpios property.
Changes in v4:
- Address review feedback from Rob, Tzung-Bi and Guenter.
- Fix GPIO direction handling and remove unnecessary locking.
- Rename the property in turris1x.dts.
Tested on a Turris 1.1 running the Turris OS build of Linux 6.6.142 with patches 2 and 3 backported. The watchdog works with periodic GPIO pings and resets the board after the pings stop. On v7.4-rc3, also tested the binding with dt_binding_check and dtbs_check, and built the driver for powerpc, and for arm64 with and without GPIOLIB. GPIO behaviour was additionally tested under QEMU.
Patch 3 can go through the powerpc tree once the binding is in.
[1] https://lore.kernel.org/r/[email protected]/
Josef Schlehofer (1):
powerpc: dts: turris1x.dts: Use wdi-gpios for the watchdog
Pali Rohár (2):
dt-bindings: watchdog: maxim,max63xx: Add wdi-gpios
watchdog: max63xx_wdt: Add support for specifying WDI logic via GPIO
.../bindings/watchdog/maxim,max63xx.yaml | 6 +++++ arch/powerpc/boot/dts/turris1x.dts | 2 +- drivers/watchdog/max63xx_wdt.c | 24 +++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-)
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH v4 1/3 dt-bindings: watchdog: maxim,max63xx: Add wdi-gpios
From: Pali Rohár <[email protected]>
On some boards only the SET pins of the watchdog are mapped to the register, and its WDI (watchdog input) pin is connected to a GPIO. The CZ.NIC Turris 1.x routers are wired this way.
Add an optional wdi-gpios property for that GPIO.
---
Notes:
Changes in v4:
- rename the property to wdi-gpios (Rob)
- wrap the description at 80 columns (Rob)
Changes in v3:
* Extend description
.../devicetree/bindings/watchdog/maxim,max63xx.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/watchdog/maxim,max63xx.yaml +6 -0
@@ -28,6 +28,12 @@ properties: description: This is a 1-byte memory-mapped address maxItems: 1 + wdi-gpios: + description: + GPIO connected to the WDI (watchdog input) pin, on boards where WDI is + not driven through the memory-mapped register. + maxItems: 1 + required: - compatible - reg
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH v4 2/3 watchdog: max63xx_wdt: Add support for specifying WDI logic via GPIO
In reply to Josef SchlehoferFrom: Pali Rohár <[email protected]>
On some boards the WDI (watchdog input) pin of the chip is connected to a GPIO, and only the SET pins are mapped to the register.
Take the GPIO from the optional wdi-gpios property. When it is present, ping the watchdog through it instead of the register.
[[email protected]: use wdi-gpios, request the GPIO as an output
with devm_gpiod_get_optional(), ping without the lock, include linux/delay.h, update the header comment]
---
Notes:
Changes in v4:
- take the GPIO from wdi-gpios
- request it with devm_gpiod_get_optional() (Tzung-Bi) and GPIOD_OUT_LOW. v3 passed GPIOD_FLAGS_BIT_DIR_OUT alone, which sets no direction
- ping without the lock, with gpiod_set_value_cansleep() (Tzung-Bi, Guenter)
- include linux/delay.h (Tzung-Bi)
- print the error once (Tzung-Bi)
- say in the commit message that the GPIO replaces the register for the ping (Tzung-Bi)
- update the comment at the top of the file
Changes in v3:
* Use gpiod_set_value()
Changes in v2:
* Usage of dev_err_probe()
* Fixing assignment of wdt->ping
* Remove clearing of wdt->gpio_wdi
* Move YAML change to separate patch
drivers/watchdog/max63xx_wdt.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/watchdog/max63xx_wdt.c +22 -2
@@ -7,8 +7,9 @@* Copyright (C) 2009 Marc Zyngier <[email protected]> * * This driver assumes the watchdog pins are memory mapped (as it is -* the case for the Arcom Zeus). Should it be connected over GPIOs or -* another interface, some abstraction will have to be introduced. +* the case for the Arcom Zeus). The WDI pin can be connected to a GPIO +* instead. Should the other pins be connected over GPIOs or another +* interface, some abstraction will have to be introduced. */ #include <linux/err.h>
@@ -18,6 +19,8 @@#include <linux/kernel.h> #include <linux/watchdog.h> #include <linux/bitops.h> +#include <linux/delay.h> +#include <linux/gpio/consumer.h> #include <linux/platform_device.h> #include <linux/spinlock.h> #include <linux/io.h>
@@ -50,6 +53,9 @@ struct max63xx_wdt {void __iomem *base;spinlock_t lock; +/* optional GPIO connected to the WDI pin */ +struct gpio_desc *gpio_wdi; +/* WDI and WSET bits write access routines */ void (*ping)(struct max63xx_wdt *wdt);void (*set)(struct max63xx_wdt *wdt,u8 set);
@@ -155,6 +161,13 @@ static const struct watchdog_info max63xx_wdt_info = { .identity = "max63xx Watchdog", }; +static void max63xx_gpio_ping (struct max63xx_wdt *wdt) +{ +gpiod_set_value_cansleep (wdt->gpio_wdi,1 ); +udelay (1 ); +gpiod_set_value_cansleep (wdt->gpio_wdi,0 ); +} +static void max63xx_mmap_ping (struct max63xx_wdt *wdt) {u8 val;
@@ -226,6 +239,13 @@ static int max63xx_wdt_probe(struct platform_device *pdev)if (err)return err; + wdt->gpio_wdi =devm_gpiod_get_optional (dev,"wdi" ,GPIOD_OUT_LOW ); +if (IS_ERR (wdt->gpio_wdi)) +return dev_err_probe (dev,PTR_ERR (wdt->gpio_wdi), +"failed to get the WDI GPIO\n" ); +if (wdt->gpio_wdi) + wdt->ping = max63xx_gpio_ping; +platform_set_drvdata (pdev, &wdt->wdd);watchdog_set_drvdata (&wdt->wdd, wdt);
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH v4 3/3 powerpc: dts: turris1x.dts: Use wdi-gpios for the watchdog
In reply to Josef SchlehoferThe watchdog node passes its WDI GPIO in a gpios property, which the maxim,max63xx binding does not define and the max63xx_wdt driver does not read. dtbs_check reports it for watchdog@2:
Unevaluated properties are not allowed ('gpios' was unexpected)
Rename it to wdi-gpios, which the binding defines and the driver reads.
---
Notes:
Changes in v4:
- new patch
arch/powerpc/boot/dts/turris1x.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/boot/dts/turris1x.dts +1 -1
@@ -363,7 +363,7 @@ */ compatible = "maxim,max6370"; reg = <0x02 0x01>; - gpios = <&gpio 11 GPIO_ACTIVE_LOW>; + wdi-gpios = <&gpio 11 GPIO_ACTIVE_LOW>; }; reboot@d {
Signature · 1 line
2.54.0 (Apple Git-157)
Re: [PATCH v4 3/3] powerpc: dts: turris1x.dts: Use wdi-gpios for the watchdog
Quoted 7 lines · Josef Schlehofer
The watchdog node passes its WDI GPIO in a gpios property, which the maxim,max63xx binding does not define and the
max63xx_wdtdriver does not read.dtbs_checkreports it for watchdog@2:Unevaluated properties are not allowed ('gpios' was unexpected)
Rename it to wdi-gpios, which the binding defines and the driver reads.
Quoted 23 lines
Signed-off-by Josef Schlehofer <[email protected]>---
Notes:
Changes in v4:
- new patcharch/powerpc/boot/dts/turris1x.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/powerpc/boot/dts/turris1x.dts +1
-1@@ -363,7 +363,7 @@ */ compatible = "maxim,max6370"; reg = <0x02 0x01>; - gpios = <&gpio 11 GPIO_ACTIVE_LOW>; + wdi-gpios = <&gpio 11 GPIO_ACTIVE_LOW>; }; reboot@d {