From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: MIME-Version: 1.0 In-Reply-To: References: <1484917398-15604-1-git-send-email-baoyou.xie@linaro.org> <1484917398-15604-3-git-send-email-baoyou.xie@linaro.org> From: Baoyou Xie Date: Sun, 22 Jan 2017 15:50:46 +0800 Message-ID: Subject: Re: [PATCH v3 3/3] watchdog: zx2967: add watchdog controller driver for ZTE's zx2967 family Content-Type: multipart/alternative; boundary=001a1140b0fa15ca260546aa2403 To: Guenter Roeck Cc: Jun Nie , wim@iguana.be, Rob Herring , mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org, Linux Kernel Mailing List , Shawn Guo , "xie.baoyou" , chen.chaokai@zte.com.cn, wang.qiang01@zte.com.cn List-ID: --001a1140b0fa15ca260546aa2403 Content-Type: text/plain; charset=UTF-8 On 22 January 2017 at 07:06, Guenter Roeck wrote: > On 01/20/2017 05:03 AM, Baoyou Xie wrote: > >> This patch adds watchdog controller driver for ZTE's zx2967 family. >> >> Signed-off-by: Baoyou Xie >> --- >> drivers/watchdog/Kconfig | 10 ++ >> drivers/watchdog/Makefile | 1 + >> drivers/watchdog/zx2967_wdt.c | 376 ++++++++++++++++++++++++++++++ >> ++++++++++++ >> 3 files changed, 387 insertions(+) >> create mode 100644 drivers/watchdog/zx2967_wdt.c >> >> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig >> index acb00b5..05093a2 100644 >> --- a/drivers/watchdog/Kconfig >> +++ b/drivers/watchdog/Kconfig >> @@ -714,6 +714,16 @@ config ASPEED_WATCHDOG >> To compile this driver as a module, choose M here: the >> module will be called aspeed_wdt. >> >> +config ZX2967_WATCHDOG >> + tristate "ZTE zx2967 SoCs watchdog support" >> + depends on ARCH_ZX >> + select WATCHDOG_CORE >> + help >> + Say Y here to include support for the watchdog timer >> + in ZTE zx2967 SoCs. >> + To compile this driver as a module, choose M here: the >> + module will be called zx2967_wdt. >> + >> # AVR32 Architecture >> >> config AT32AP700X_WDT >> diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile >> index 0c3d35e..bf2d296 100644 >> --- a/drivers/watchdog/Makefile >> +++ b/drivers/watchdog/Makefile >> @@ -82,6 +82,7 @@ obj-$(CONFIG_BCM7038_WDT) += bcm7038_wdt.o >> obj-$(CONFIG_ATLAS7_WATCHDOG) += atlas7_wdt.o >> obj-$(CONFIG_RENESAS_WDT) += renesas_wdt.o >> obj-$(CONFIG_ASPEED_WATCHDOG) += aspeed_wdt.o >> +obj-$(CONFIG_ZX2967_WATCHDOG) += zx2967_wdt.o >> >> # AVR32 Architecture >> obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o >> diff --git a/drivers/watchdog/zx2967_wdt.c b/drivers/watchdog/zx2967_wdt. >> c >> new file mode 100644 >> index 0000000..a5656d0 >> --- /dev/null >> +++ b/drivers/watchdog/zx2967_wdt.c >> @@ -0,0 +1,376 @@ >> +/* >> + * watchdog driver for ZTE's zx2967 family >> + * >> + * Copyright (C) 2017 ZTE Ltd. >> + * >> + * Author: Baoyou Xie >> + * >> + * License terms: GNU General Public License (GPL) version 2 >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#define ZX2967_WDT_CFG_REG 0x4 >> +#define ZX2967_WDT_LOAD_REG 0x8 >> +#define ZX2967_WDT_REFRESH_REG 0x18 >> +#define ZX2967_WDT_START_REG 0x1c >> + >> +#define ZX2967_WDT_REFRESH_MASK 0x3f >> + >> +#define ZX2967_WDT_CFG_DIV(n) ((((n) & 0xff) - 1) << 8) >> +#define ZX2967_WDT_START_EN 0x1 >> + >> +#define ZX2967_WDT_WRITEKEY 0x12340000 >> + >> +#define ZX2967_WDT_DIV_DEFAULT 16 >> +#define ZX2967_WDT_DEFAULT_TIMEOUT 32 >> +#define ZX2967_WDT_MIN_TIMEOUT 1 >> +#define ZX2967_WDT_MAX_TIMEOUT 500 >> > > Is that based on a real limit or an arbitrary value ? > > It's based on a real limit. In fact, the real limit is 524. > +#define ZX2967_WDT_MAX_COUNT 0xffff >> + >> +#define ZX2967_WDT_FLAG_REBOOT_MON (1 << 0) >> > > BIT ? > > > + >> +struct zx2967_wdt { >> + struct device *dev; >> + struct clk *clock; >> + void __iomem *reg_base; >> + unsigned int conf; >> + unsigned int load; >> + unsigned int flags; >> + struct watchdog_device wdt_device; >> + struct notifier_block restart_handler; >> + struct notifier_block reboot_handler; >> +}; >> + >> +static inline u32 zx2967_wdt_readl(struct zx2967_wdt *wdt, u16 reg) >> +{ >> + return readl_relaxed(wdt->reg_base + reg); >> +} >> + >> +static inline void zx2967_wdt_writel(struct zx2967_wdt *wdt, u16 reg, >> u32 val) >> +{ >> + writel_relaxed(val | ZX2967_WDT_WRITEKEY, wdt->reg_base + reg); >> +} >> + >> +static void zx2967_wdt_refresh(struct zx2967_wdt *wdt) >> +{ >> + u32 val; >> + >> + val = zx2967_wdt_readl(wdt, ZX2967_WDT_REFRESH_REG); >> + val ^= ZX2967_WDT_REFRESH_MASK; >> + zx2967_wdt_writel(wdt, ZX2967_WDT_REFRESH_REG, val); >> +} >> + >> +static unsigned int >> +__zx2967_wdt_set_timeout(struct zx2967_wdt *wdt, unsigned int timeout) >> +{ >> + unsigned int freq = clk_get_rate(wdt->clock); >> > > The clock frequency is set to 32 kHz. It seems unnecessary to re-read it > whenever the timeout changes. Also, ... > > + unsigned int divisor = ZX2967_WDT_DIV_DEFAULT; >> + unsigned int count; >> + >> + count = timeout * freq; >> + if (count > divisor * ZX2967_WDT_MAX_COUNT) >> + divisor = DIV_ROUND_UP(count, ZX2967_WDT_MAX_COUNT); >> + count = DIV_ROUND_UP(count, divisor); >> + zx2967_wdt_writel(wdt, ZX2967_WDT_CFG_REG, >> ZX2967_WDT_CFG_DIV(divisor)); >> + zx2967_wdt_writel(wdt, ZX2967_WDT_LOAD_REG, count); >> + zx2967_wdt_refresh(wdt); >> + wdt->load = count; >> + >> + return (count * divisor) / freq; >> > > ... if you think it can change from underneath you, you'll also need to > make sure > it is not 0, to avoid a nasty surprise here. Of course, if it does change, > you'll > have no idea what the actual timeout is at any given time, and the driver > won't work. > > +} >> + >> +static int zx2967_wdt_set_timeout(struct watchdog_device *wdd, >> + unsigned int timeout) >> +{ >> + struct zx2967_wdt *wdt = watchdog_get_drvdata(wdd); >> + >> + if (watchdog_timeout_invalid(&wdt->wdt_device, timeout)) { >> + dev_err(wdt->dev, "timeout %d is invalid\n", timeout); >> + return -EINVAL; >> + } >> > > This function is called from the infrastructure. Let's trust the > infrastructure > to check the valid range before calling this code. > > + >> + wdd->timeout = __zx2967_wdt_set_timeout(wdt, timeout); >> + >> + return 0; >> +} >> + >> +static void __zx2967_wdt_start(struct zx2967_wdt *wdt) >> +{ >> + u32 val; >> + >> + val = zx2967_wdt_readl(wdt, ZX2967_WDT_START_REG); >> + val |= ZX2967_WDT_START_EN; >> + zx2967_wdt_writel(wdt, ZX2967_WDT_START_REG, val); >> +} >> + >> +static void __zx2967_wdt_stop(struct zx2967_wdt *wdt) >> +{ >> + u32 val; >> + >> + val = zx2967_wdt_readl(wdt, ZX2967_WDT_START_REG); >> + val &= ~ZX2967_WDT_START_EN; >> + zx2967_wdt_writel(wdt, ZX2967_WDT_START_REG, val); >> +} >> + >> +static int zx2967_wdt_start(struct watchdog_device *wdd) >> +{ >> + struct zx2967_wdt *wdt = watchdog_get_drvdata(wdd); >> + >> + __zx2967_wdt_stop(wdt); >> + zx2967_wdt_set_timeout(wdd, wdd->timeout); >> > > This seems inconsistent. First, the watchdog should not already be > started when this function is called. Second, if it is in fact necessary > to stop the watchdog before updating its timeout, you might want to > consider stopping it in the set_timeout function, because that > function _will_ be called if the timeout is updated while the > watchdog is running. > > > + __zx2967_wdt_start(wdt); >> + >> + return 0; >> +} >> + >> +static int zx2967_wdt_stop(struct watchdog_device *wdd) >> +{ >> + struct zx2967_wdt *wdt = watchdog_get_drvdata(wdd); >> + >> + __zx2967_wdt_stop(wdt); >> + >> + return 0; >> +} >> + >> +static int zx2967_wdt_keepalive(struct watchdog_device *wdd) >> +{ >> + struct zx2967_wdt *wdt = watchdog_get_drvdata(wdd); >> + >> + zx2967_wdt_refresh(wdt); >> + >> + return 0; >> +} >> + >> +#define ZX2967_WDT_OPTIONS \ >> + (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE) >> +static const struct watchdog_info zx2967_wdt_ident = { >> + .options = ZX2967_WDT_OPTIONS, >> + .firmware_version = 0, >> + .identity = "zx2967 watchdog", >> +}; >> + >> +static struct watchdog_ops zx2967_wdt_ops = { >> + .owner = THIS_MODULE, >> + .start = zx2967_wdt_start, >> + .stop = zx2967_wdt_stop, >> + .ping = zx2967_wdt_keepalive, >> + .set_timeout = zx2967_wdt_set_timeout, >> +}; >> + >> +static void zx2967_wdt_fix_sysdown(struct zx2967_wdt *wdt) >> +{ >> + __zx2967_wdt_stop(wdt); >> + __zx2967_wdt_set_timeout(wdt, 15); >> + __zx2967_wdt_start(wdt); >> +} >> > > I am really not at all in favor of this code. It force-sets a watchdog > to 15 seconds later, if it was enabled or not. > > I don't necessarily oppose the idea in general, but it would have to be > configurable and part of the infrastructure. > > I agree you all. In fact, these codes implement the policy witch is part of products, and don't necessarily place them here. > > + >> +static int zx2967_wdt_notify_sys(struct notifier_block *this, >> + unsigned long code, void *unused) >> +{ >> + struct zx2967_wdt *wdt = container_of(this, struct zx2967_wdt, >> + reboot_handler); >> + >> + wdt->flags |= ZX2967_WDT_FLAG_REBOOT_MON; >> + switch (code) { >> + case SYS_HALT: >> + case SYS_POWER_OFF: >> + case SYS_RESTART: >> + zx2967_wdt_fix_sysdown(wdt); >> + break; >> + default: >> + break; >> + } >> + >> + return 0; >> +} >> + >> +static int zx2967_wdt_restart(struct notifier_block *this, >> + unsigned long mode, void *cmd) >> +{ >> + struct zx2967_wdt *wdt; >> + >> + wdt = container_of(this, struct zx2967_wdt, restart_handler); >> + >> + zx2967_wdt_stop(&wdt->wdt_device); >> + >> + zx2967_wdt_writel(wdt, ZX2967_WDT_LOAD_REG, 0x80); >> + zx2967_wdt_refresh(wdt); >> + zx2967_wdt_writel(wdt, ZX2967_WDT_START_REG, ZX2967_WDT_START_EN); >> + >> + zx2967_wdt_start(&wdt->wdt_device); >> + /* wait for reset*/ >> + mdelay(500); >> + >> + return NOTIFY_DONE; >> +} >> + >> +static void zx2967_wdt_reset_sysctrl(struct device *dev) >> +{ >> + int ret; >> + struct device_node *np = NULL; >> + void __iomem *regmap; >> + unsigned int offset, mask, config; >> + struct of_phandle_args out_args; >> + >> + ret = of_parse_phandle_with_fixed_args(dev->of_node, >> + "zte,wdt-reset-sysctrl", 3, 0, &out_args); >> + if (ret) { >> + dev_info(dev, "failed to parse zte,wdt-reset-sysctrl"); >> > > Why this message ? The property is optional. There is no "failure". > > Repeating the information in the devicetree description: > > zte,wdt-reset-sysctrl : Directs how to reset system by the > watchdog. > > Given the context, and the provided implementation, I can only assume that > this is supposed to mean which action shall be taken when the watchdog > triggers, > and that the bit mask provided is supposed to configure that action. If so, > that should be explained in the devicetree description, and not be hidden > in magic register values. > > The devicetree description is ok. > + return; >> + } >> + offset = out_args.args[0]; >> + config = out_args.args[1]; >> + mask = out_args.args[2]; >> + >> + regmap = syscon_node_to_regmap(out_args.np); >> + if (IS_ERR(regmap)) >> + goto out; >> + >> + regmap_update_bits(regmap, offset, mask, config); >> > > > I don't really see the value of the local variables. > > Are you sure? I add the local variables in V3. > +out: >> + of_node_put(np); >> > > I don't really see where np is set to anything but NULL. > > +} >> + >> +static int zx2967_wdt_probe(struct platform_device *pdev) >> +{ >> + struct device *dev; >> + struct zx2967_wdt *wdt; >> + struct resource *base; >> + int ret = 0; >> > > Unnecessary initialization. > > + >> + struct reset_control *rstc; >> > > No empty lines between variable declarations, please. > > + >> + dev = &pdev->dev; >> > > Can be initialized above. > > + >> + wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); >> + if (!wdt) >> + return -ENOMEM; >> + >> + platform_set_drvdata(pdev, wdt); >> + >> + wdt->dev = dev; >> > > This is only used by an error message in the set_timeout function, > which is unnecessary. > > + wdt->wdt_device.info = &zx2967_wdt_ident; >> + wdt->wdt_device.ops = &zx2967_wdt_ops; >> + wdt->wdt_device.timeout = ZX2967_WDT_DEFAULT_TIMEOUT; >> + wdt->wdt_device.max_timeout = ZX2967_WDT_MAX_TIMEOUT; >> + wdt->wdt_device.min_timeout = ZX2967_WDT_MIN_TIMEOUT; >> + wdt->wdt_device.parent = &pdev->dev; >> + >> + base = platform_get_resource(pdev, IORESOURCE_MEM, 0); >> + wdt->reg_base = devm_ioremap_resource(dev, base); >> + if (IS_ERR(wdt->reg_base)) { >> + dev_err(dev, "ioremap failed\n"); >> + return PTR_ERR(wdt->reg_base); >> + } >> + >> + zx2967_wdt_reset_sysctrl(dev); >> + >> + wdt->reboot_handler.notifier_call = zx2967_wdt_notify_sys; >> + register_reboot_notifier(&wdt->reboot_handler); >> > > Without ever unregistering it ? Did you try to unload the driver and > reboot ? > > + wdt->clock = devm_clk_get(dev, NULL); >> + if (IS_ERR(wdt->clock)) { >> + dev_err(dev, "failed to find watchdog clock source\n"); >> + return PTR_ERR(wdt->clock); >> + } >> + >> + ret = clk_prepare_enable(wdt->clock); >> + if (ret < 0) { >> + dev_err(dev, "failed to enable clock\n"); >> + return ret; >> + } >> + clk_set_rate(wdt->clock, 32768); >> + >> + rstc = devm_reset_control_get(dev, NULL); >> + if (IS_ERR(rstc)) { >> + dev_err(dev, "failed to get rstc"); >> + ret = PTR_ERR(rstc); >> + goto fail_get_reset_control; >> + } >> + >> + reset_control_assert(rstc); >> + mdelay(10); >> + reset_control_deassert(rstc); >> > > There is this reset, and the reset in reset_sysctrl above. > Are they both necessary ? > > Here, we reset watchdog itself, but reset_sysctrl is used to reset system. > + watchdog_set_drvdata(&wdt->wdt_device, wdt); >> + >> + watchdog_init_timeout(&wdt->wdt_device, >> + ZX2967_WDT_DEFAULT_TIMEOUT, dev); >> > > What is the purpose of this call ? It sets the timeout to the default > timeout, > which is already set, and it does not use the value from devicetree since > the > value passed is != 0. > > + watchdog_set_nowayout(&wdt->wdt_device, WATCHDOG_NOWAYOUT); >> + >> + zx2967_wdt_stop(&wdt->wdt_device); >> > > The watchdog was reset twice above. Is this call really necessary ? > > + >> + ret = watchdog_register_device(&wdt->wdt_device); >> + if (ret) >> + goto fail_register; >> + >> + wdt->restart_handler.notifier_call = zx2967_wdt_restart; >> + wdt->restart_handler.priority = 128; >> + ret = register_restart_handler(&wdt->restart_handler); >> + if (ret) { >> + dev_err(dev, "cannot register restart handler, %d\n", >> ret); >> + goto fail_restart; >> + } >> + >> > Why not use the infrastructure ? > > + dev_info(dev, "watchdog enabled (timeout=%d sec, nowayout=%d)", >> + wdt->wdt_device.timeout, WATCHDOG_NOWAYOUT); >> + >> + return 0; >> + >> +fail_get_reset_control: >> +fail_restart: >> > > Please no double labels to the same code. > > + watchdog_unregister_device(&wdt->wdt_device); >> +fail_register: >> + clk_disable_unprepare(wdt->clock); >> + return ret; >> +} >> + >> +static int zx2967_wdt_remove(struct platform_device *pdev) >> +{ >> + struct zx2967_wdt *wdt = platform_get_drvdata(pdev); >> + >> + unregister_restart_handler(&wdt->restart_handler); >> + watchdog_unregister_device(&wdt->wdt_device); >> + clk_disable_unprepare(wdt->clock); >> + >> + return 0; >> +} >> + >> +static void zx2967_wdt_shutdown(struct platform_device *pdev) >> +{ >> + struct zx2967_wdt *wdt = platform_get_drvdata(pdev); >> + >> + if (!(wdt->flags & ZX2967_WDT_FLAG_REBOOT_MON)) >> + zx2967_wdt_stop(&wdt->wdt_device); >> > > As mentioned before, the whole reboot handling is highly unusual. > > I don't really like the idea of bypassing the infrastructure > (such as watchdog_stop_on_reboot()) for driver specific special behavior. > If such behavior is useful, it should be useful for all watchdog drivers, > and be defined in the infrastructure. > > > +} >> + >> +static const struct of_device_id zx2967_wdt_match[] = { >> + { .compatible = "zte,zx296718-wdt", }, >> + {} >> +}; >> +MODULE_DEVICE_TABLE(of, zx2967_wdt_match); >> + >> +static struct platform_driver zx2967_wdt_driver = { >> + .probe = zx2967_wdt_probe, >> + .remove = zx2967_wdt_remove, >> + .shutdown = zx2967_wdt_shutdown, >> + .driver = { >> + .name = "zx2967-wdt", >> + .of_match_table = of_match_ptr(zx2967_wdt_match), >> + }, >> +}; >> +module_platform_driver(zx2967_wdt_driver); >> + >> +MODULE_AUTHOR("Baoyou Xie "); >> +MODULE_DESCRIPTION("ZTE zx2967 Watchdog Device Driver"); >> +MODULE_LICENSE("GPL v2"); >> >> > --001a1140b0fa15ca260546aa2403 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On 22 January 2017 at 07:06, Guenter Roeck <linux@roeck-us.net>= ; wrote:
On 01/20/2017 05:03 AM, Baoyo= u Xie wrote:
This patch adds watchdog controller driver for ZTE's zx2967 family.

Signed-off-by: Baoyou Xie <baoyou.xie@linaro.org>
---
=C2=A0drivers/watchdog/Kconfig=C2=A0 =C2=A0 =C2=A0 |=C2=A0 10 ++
=C2=A0drivers/watchdog/Makefile=C2=A0 =C2=A0 =C2=A0|=C2=A0 =C2=A01 +
=C2=A0drivers/watchdog/zx2967_wdt.c | 376 ++++++++++++++++++++++++++++++++++++++++++
=C2=A03 files changed, 387 insertions(+)
=C2=A0create mode 100644 drivers/watchdog/zx2967_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index acb00b5..05093a2 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -714,6 +714,16 @@ config ASPEED_WATCHDOG
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 To compile this driver as a module, choo= se M here: the
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 module will be called aspeed_wdt.

+config ZX2967_WATCHDOG
+=C2=A0 =C2=A0 =C2=A0 =C2=A0tristate "ZTE zx2967 SoCs watchdog support= "
+=C2=A0 =C2=A0 =C2=A0 =C2=A0depends on ARCH_ZX
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select WATCHDOG_CORE
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Say Y here to include support for the wa= tchdog timer
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0in ZTE zx2967 SoCs.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0To compile this driver as a module, choo= se M here: the
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0module will be called zx2967_wdt.
+
=C2=A0# AVR32 Architecture

=C2=A0config AT32AP700X_WDT
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 0c3d35e..bf2d296 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -82,6 +82,7 @@ obj-$(CONFIG_BCM7038_WDT) +=3D bcm7038_wdt.o
=C2=A0obj-$(CONFIG_ATLAS7_WATCHDOG) +=3D atlas7_wdt.o
=C2=A0obj-$(CONFIG_RENESAS_WDT) +=3D renesas_wdt.o
=C2=A0obj-$(CONFIG_ASPEED_WATCHDOG) +=3D aspeed_wdt.o
+obj-$(CONFIG_ZX2967_WATCHDOG) +=3D zx2967_wdt.o

=C2=A0# AVR32 Architecture
=C2=A0obj-$(CONFIG_AT32AP700X_WDT) +=3D at32ap700x_wdt.o
diff --git a/drivers/watchdog/zx2967_wdt.c b/drivers/watchdog/zx2967_w= dt.c
new file mode 100644
index 0000000..a5656d0
--- /dev/null
+++ b/drivers/watchdog/zx2967_wdt.c
@@ -0,0 +1,376 @@
+/*
+ * watchdog driver for ZTE's zx2967 family
+ *
+ * Copyright (C) 2017 ZTE Ltd.
+ *
+ * Author: Baoyou Xie <baoyou.xie@linaro.org>
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/reboot.h>
+#include <linux/regmap.h>
+#include <linux/reset.h>
+#include <linux/watchdog.h>
+
+#define ZX2967_WDT_CFG_REG=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A00x4
+#define ZX2967_WDT_LOAD_REG=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 0x8
+#define ZX2967_WDT_REFRESH_REG=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A00x18
+#define ZX2967_WDT_START_REG=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A00x1c
+
+#define ZX2967_WDT_REFRESH_MASK=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x3f
+
+#define ZX2967_WDT_CFG_DIV(n)=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 ((((n) & 0xff) - 1) << 8)
+#define ZX2967_WDT_START_EN=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 0x1
+
+#define ZX2967_WDT_WRITEKEY=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 0x12340000
+
+#define ZX2967_WDT_DIV_DEFAULT=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A016
+#define ZX2967_WDT_DEFAULT_TIMEOUT=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A032
+#define ZX2967_WDT_MIN_TIMEOUT=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A01
+#define ZX2967_WDT_MAX_TIMEOUT=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0500

Is that based on a real limit or an arbitrary value ?

It's based on a real limit. In fact, the r= eal limit is 524.
=C2=A0
+#define ZX2967_WDT_MAX_COUNT=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A00xffff
+
+#define ZX2967_WDT_FLAG_REBOOT_MON=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(1 << 0)

BIT ?

<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">

+
+struct zx2967_wdt {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct device=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0*dev;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct clk=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 *clock;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0void __iomem=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 *reg_base;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned int=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 conf;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned int=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 load;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned int=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 flags;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct watchdog_device=C2=A0 wdt_device;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct notifier_block=C2=A0 =C2=A0restart_handl= er;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct notifier_block=C2=A0 =C2=A0reboot_handle= r;
+};
+
+static inline u32 zx2967_wdt_readl(struct zx2967_wdt *wdt, u16 reg)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return readl_relaxed(wdt->reg_base + reg); +}
+
+static inline void zx2967_wdt_writel(struct zx2967_wdt *wdt, u16 reg, u32 = val)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0writel_relaxed(val | ZX2967_WDT_WRITEKEY, wdt-&= gt;reg_base + reg);
+}
+
+static void zx2967_wdt_refresh(struct zx2967_wdt *wdt)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0u32 val;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0val =3D zx2967_wdt_readl(wdt, ZX2967_WDT_REFRES= H_REG);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0val ^=3D ZX2967_WDT_REFRESH_MASK;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_writel(wdt, ZX2967_WDT_REFRESH_REG, = val);
+}
+
+static unsigned int
+__zx2967_wdt_set_timeout(struct zx2967_wdt *wdt, unsigned int timeout= )
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned int freq =3D clk_get_rate(wdt->cloc= k);

The clock frequency is set to 32 kHz. It seems unnecessary to re-read it whenever the timeout changes. Also, ...

+=C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned int divisor =3D ZX2967_WDT_DIV_DEFAULT= ;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned int count;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0count =3D timeout * freq;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (count > divisor * ZX2967_WDT_MAX_COUNT)<= br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0divisor =3D DIV_ROU= ND_UP(count, ZX2967_WDT_MAX_COUNT);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0count =3D DIV_ROUND_UP(count, divisor);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_writel(wdt, ZX2967_WDT_CFG_REG, ZX29= 67_WDT_CFG_DIV(divisor));
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_writel(wdt, ZX2967_WDT_LOAD_REG, cou= nt);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_refresh(wdt);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt->load =3D count;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return (count * divisor) / freq;

... if you think it can change from underneath you, you'll also need to= make sure
it is not 0, to avoid a nasty surprise here. Of course, if it does change, = you'll
have no idea what the actual timeout is at any given time, and the driver w= on't work.

+}
+
+static int zx2967_wdt_set_timeout(struct watchdog_device *wdd,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned int timeout)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct zx2967_wdt *wdt =3D watchdog_get_drvdata= (wdd);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (watchdog_timeout_invalid(&wdt->= wdt_device, timeout)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dev_err(wdt->dev= , "timeout %d is invalid\n", timeout);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -EINVAL;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}

This function is called from the infrastructure. Let's trust the infras= tructure
to check the valid range before calling this code.

+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdd->timeout =3D __zx2967_wdt_set_timeout(wd= t, timeout);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return 0;
+}
+
+static void __zx2967_wdt_start(struct zx2967_wdt *wdt)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0u32 val;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0val =3D zx2967_wdt_readl(wdt, ZX2967_WDT_START_= REG);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0val |=3D ZX2967_WDT_START_EN;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_writel(wdt, ZX2967_WDT_START_REG, va= l);
+}
+
+static void __zx2967_wdt_stop(struct zx2967_wdt *wdt)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0u32 val;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0val =3D zx2967_wdt_readl(wdt, ZX2967_WDT_START_= REG);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0val &=3D ~ZX2967_WDT_START_EN;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_writel(wdt, ZX2967_WDT_START_REG, va= l);
+}
+
+static int zx2967_wdt_start(struct watchdog_device *wdd)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct zx2967_wdt *wdt =3D watchdog_get_drvdata= (wdd);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0__zx2967_wdt_stop(wdt);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_set_timeout(wdd, wdd->timeout);

This seems inconsistent. First, the watchdog should not already be
started when this function is called. Second, if it is in fact necessary to stop the watchdog before updating its timeout, you might want to
consider stopping it in the set_timeout function, because that
function _will_ be called if the timeout is updated while the
watchdog is running.


+=C2=A0 =C2=A0 =C2=A0 =C2=A0__zx2967_wdt_start(wdt);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return 0;
+}
+
+static int zx2967_wdt_stop(struct watchdog_device *wdd)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct zx2967_wdt *wdt =3D watchdog_get_drvdata= (wdd);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0__zx2967_wdt_stop(wdt);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return 0;
+}
+
+static int zx2967_wdt_keepalive(struct watchdog_device *wdd)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct zx2967_wdt *wdt =3D watchdog_get_drvdata= (wdd);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_refresh(wdt);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return 0;
+}
+
+#define ZX2967_WDT_OPTIONS \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF= _MAGICCLOSE)
+static const struct watchdog_info zx2967_wdt_ident =3D {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0.options=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D= =C2=A0 =C2=A0 =C2=A0ZX2967_WDT_OPTIONS,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0.firmware_version =3D=C2=A0 =C2=A0 =C2=A00,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0.identity=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D= =C2=A0 =C2=A0 =C2=A0"zx2967 watchdog",
+};
+
+static struct watchdog_ops zx2967_wdt_ops =3D {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0.owner =3D THIS_MODULE,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0.start =3D zx2967_wdt_start,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0.stop =3D zx2967_wdt_stop,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0.ping =3D zx2967_wdt_keepalive,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0.set_timeout =3D zx2967_wdt_set_timeout,
+};
+
+static void zx2967_wdt_fix_sysdown(struct zx2967_wdt *wdt)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0__zx2967_wdt_stop(wdt);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0__zx2967_wdt_set_timeout(wdt, 15);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0__zx2967_wdt_start(wdt);
+}

I am really not at all in favor of this code. It force-sets a watchdog
to 15 seconds later, if it was enabled or not.

I don't necessarily oppose the idea in general, but it would have to be=
configurable and part of the infrastructure.
I agree you all. In fact, these codes imple= ment the policy witch is part of products, and don't necessarily place = them here.
=C2=A0

+
+static int zx2967_wdt_notify_sys(struct notifier_block *this,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 unsigned long code, void *unused)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct zx2967_wdt *wdt =3D container_of(this, s= truct zx2967_wdt,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0reboot_handler);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt->flags |=3D ZX2967_WDT_FLAG_REBOOT_MON;<= br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0switch (code) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0case SYS_HALT:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0case SYS_POWER_OFF:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0case SYS_RESTART:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_fix_sysd= own(wdt);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return 0;
+}
+
+static int zx2967_wdt_restart(struct notifier_block *this,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long mode, void *cmd)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct zx2967_wdt *wdt;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt =3D container_of(this, struct zx2967_wdt, r= estart_handler);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_stop(&wdt->wdt_device);<= br> +
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_writel(wdt, ZX2967_WDT_LOAD_REG, 0x8= 0);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_refresh(wdt);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_writel(wdt, ZX2967_WDT_START_REG, ZX= 2967_WDT_START_EN);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_start(&wdt->wdt_device);=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* wait for reset*/
+=C2=A0 =C2=A0 =C2=A0 =C2=A0mdelay(500);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return NOTIFY_DONE;
+}
+
+static void zx2967_wdt_reset_sysctrl(struct device *dev)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0int ret;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct device_node *np =3D NULL;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0void __iomem *regmap;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned int offset, mask, config;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct of_phandle_args out_args;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D of_parse_phandle_with_fixed_args(d= ev->of_node,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0"zte,wdt-reset-sysctrl", 3, 0, &out_args);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (ret) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dev_info(dev, "= ;failed to parse zte,wdt-reset-sysctrl");

Why this message ? The property is optional. There is no "failure"= ;.

Repeating the information in the devicetree description:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 zte,wdt-reset-sysctrl : Directs how to reset sy= stem by the watchdog.

Given the context, and the provided implementation, I can only assume that<= br> this is supposed to mean which action shall be taken when the watchdog trig= gers,
and that the bit mask provided is supposed to configure that action. If so,=
that should be explained in the devicetree description, and not be hidden in magic register values.

The devicetree description is ok.
=C2=A0
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+=C2=A0 =C2=A0 =C2=A0 =C2=A0offset =3D out_args.args[0];
+=C2=A0 =C2=A0 =C2=A0 =C2=A0config =3D out_args.args[1];
+=C2=A0 =C2=A0 =C2=A0 =C2=A0mask =3D out_args.args[2];
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0regmap =3D syscon_node_to_regmap(out_args.np)= ;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (IS_ERR(regmap))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto out;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0regmap_update_bits(regmap, offset, mask, config= );


I don't really see the value of the local variables.

Are you sure? I add the local variables in V3.
=C2=A0
+out:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0of_node_put(np);

I don't really see where np is set to anything but NULL.

+}
+
+static int zx2967_wdt_probe(struct platform_device *pdev)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct device *dev;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct zx2967_wdt *wdt;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct resource *base;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0int ret =3D 0;

Unnecessary initialization.

+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct reset_control *rstc;

No empty lines between variable declarations, please.

+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0dev =3D &pdev->dev;

Can be initialized above.

+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt =3D devm_kzalloc(dev, sizeof(*wdt), GFP_KER= NEL);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!wdt)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -ENOMEM;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0platform_set_drvdata(pdev, wdt);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt->dev =3D dev;

This is only used by an error message in the set_timeout function,
which is unnecessary.

+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt->wdt_device.info =3D &zx2967_wdt_i= dent;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt->wdt_device.ops =3D &zx2967_wdt_ops;=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt->wdt_device.timeout =3D ZX2967_WDT_DEFAU= LT_TIMEOUT;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt->wdt_device.max_timeout =3D ZX2967_WDT_M= AX_TIMEOUT;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt->wdt_device.min_timeout =3D ZX2967_WDT_M= IN_TIMEOUT;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt->wdt_device.parent =3D &pdev->dev= ;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0base =3D platform_get_resource(pdev, IORESOURCE= _MEM, 0);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt->reg_base =3D devm_ioremap_resource(dev,= base);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (IS_ERR(wdt->reg_base)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dev_err(dev, "= ioremap failed\n");
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return PTR_ERR(wdt-= >reg_base);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_reset_sysctrl(dev);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt->reboot_handler.notifier_call =3D z= x2967_wdt_notify_sys;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0register_reboot_notifier(&wdt->rebo= ot_handler);

Without ever unregistering it ? Did you try to unload the driver and reboot= ?

+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt->clock =3D devm_clk_get(dev, NULL);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (IS_ERR(wdt->clock)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dev_err(dev, "= failed to find watchdog clock source\n");
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return PTR_ERR(wdt-= >clock);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D clk_prepare_enable(wdt->clock);=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (ret < 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dev_err(dev, "= failed to enable clock\n");
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return ret;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+=C2=A0 =C2=A0 =C2=A0 =C2=A0clk_set_rate(wdt->clock, 32768);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0rstc =3D devm_reset_control_get(dev, NULL);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (IS_ERR(rstc)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dev_err(dev, "= failed to get rstc");
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D PTR_ERR(rst= c);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto fail_get_reset= _control;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0reset_control_assert(rstc);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0mdelay(10);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0reset_control_deassert(rstc);

There is this reset, and the reset in reset_sysctrl above.
Are they both necessary ?

Here, we reset watchdog itself, but reset_sysc= trl is used to reset system.
=C2=A0
+=C2=A0 =C2=A0 =C2=A0 =C2=A0watchdog_set_drvdata(&wdt->wdt_devi= ce, wdt);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0watchdog_init_timeout(&wdt->wdt_dev= ice,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ZX2967_WDT_DEFAULT_TIMEOUT, dev);

What is the purpose of this call ? It sets the timeout to the default timeo= ut,
which is already set, and it does not use the value from devicetree since t= he
value passed is !=3D 0.

+=C2=A0 =C2=A0 =C2=A0 =C2=A0watchdog_set_nowayout(&wdt->wdt_dev= ice, WATCHDOG_NOWAYOUT);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_stop(&wdt->wdt_device);<= br>

The watchdog was reset twice above. Is this call really necessary ?

+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D watchdog_register_device(&wdt-= >wdt_device);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (ret)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto fail_register;=
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt->restart_handler.notifier_call =3D = zx2967_wdt_restart;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0wdt->restart_handler.priority =3D 128;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D register_restart_handler(&wdt-= >restart_handler);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (ret) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dev_err(dev, "= cannot register restart handler, %d\n", ret);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto fail_restart;<= br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+
Why not use the infrastructure ?

+=C2=A0 =C2=A0 =C2=A0 =C2=A0dev_info(dev, "watchdog enabled (timeout= =3D%d sec, nowayout=3D%d)",
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 wdt->wdt_device= .timeout, WATCHDOG_NOWAYOUT);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return 0;
+
+fail_get_reset_control:
+fail_restart:

Please no double labels to the same code.

+=C2=A0 =C2=A0 =C2=A0 =C2=A0watchdog_unregister_device(&wdt->wd= t_device);
+fail_register:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0clk_disable_unprepare(wdt->clock);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return ret;
+}
+
+static int zx2967_wdt_remove(struct platform_device *pdev)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct zx2967_wdt *wdt =3D platform_get_drvdata= (pdev);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0unregister_restart_handler(&wdt->re= start_handler);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0watchdog_unregister_device(&wdt->wd= t_device);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0clk_disable_unprepare(wdt->clock);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return 0;
+}
+
+static void zx2967_wdt_shutdown(struct platform_device *pdev)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct zx2967_wdt *wdt =3D platform_get_drvdata= (pdev);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!(wdt->flags & ZX2967_WDT_FLAG_REBOO= T_MON))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0zx2967_wdt_stop(&am= p;wdt->wdt_device);

As mentioned before, the whole reboot handling is highly unusual.

I don't really like the idea of bypassing the infrastructure
(such as watchdog_stop_on_reboot()) for driver specific special behavior. If such behavior is useful, it should be useful for all watchdog drivers, and be defined in the infrastructure.


+}
+
+static const struct of_device_id zx2967_wdt_match[] =3D {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0{ .compatible =3D "zte,zx296718-wdt",= },
+=C2=A0 =C2=A0 =C2=A0 =C2=A0{}
+};
+MODULE_DEVICE_TABLE(of, zx2967_wdt_match);
+
+static struct platform_driver zx2967_wdt_driver =3D {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0.probe=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D zx= 2967_wdt_probe,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0.remove=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D zx= 2967_wdt_remove,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0.shutdown=C2=A0 =C2=A0 =C2=A0 =C2=A0=3D zx2967_= wdt_shutdown,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0.driver=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D {<= br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0.name=C2=A0 =C2=A0= =3D "zx2967-wdt",
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0.of_match_table =3D= of_match_ptr(zx2967_wdt_match),
+=C2=A0 =C2=A0 =C2=A0 =C2=A0},
+};
+module_platform_driver(zx2967_wdt_driver);
+
+MODULE_AUTHOR("Baoyou Xie <baoyou.xie@linaro.org>");
+MODULE_DESCRIPTION("ZTE zx2967 Watchdog Device Driver");
+MODULE_LICENSE("GPL v2");



--001a1140b0fa15ca260546aa2403--