Skip to contentSkip to conversation

Add watchdog driver for Sunplus SP7021 SoC

PATCH Superseded Xiantao Hu 4 participants 17 messages Nov 12, 2021 – Dec 3, 2021

Subsystems (3)

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Xiantao Hu

author maintainer
#0 lore raw

cover Add watchdog driver for Sunplus SP7021 SoC

This is a patch series for watchdog driver for Sunplus SP7021 SoC.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html

Xiantao Hu (2):
watchdog: Add watchdog driver for Sunplus SP7021
dt-bindings: watchdog: Add Sunplus SP7021 WDT devicetree bindings
documentation

 .../bindings/watchdog/sunplus,sp7021-wdt.yaml |  47 +++
 MAINTAINERS                                   |   7 +
 drivers/watchdog/Kconfig                      |  11 +
 drivers/watchdog/Makefile                     |   1 +
 drivers/watchdog/sunplus_wdt.c                | 297 ++++++++++++++++++
 5 files changed, 363 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml
 create mode 100644 drivers/watchdog/sunplus_wdt.c
Signature · 1 line
2.33.1
author maintainer
#1 lore raw

PATCH 1/2 watchdog: Add watchdog driver for Sunplus SP7021

Sunplus SP7021 requires watchdog timer support.
Add watchdog driver to enable this.

---
 MAINTAINERS                    |   6 +
 drivers/watchdog/Kconfig       |  11 ++
 drivers/watchdog/Makefile      |   1 +
 drivers/watchdog/sunplus_wdt.c | 297 +++++++++++++++++++++++++++++++++
 4 files changed, 315 insertions(+)
 create mode 100644 drivers/watchdog/sunplus_wdt.c
MAINTAINERS +6 -0
index e0bca0de0..f6a328772 100644
@@ -17933,6 +17933,12 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/net/ethernet/dlink/sundance.c
 
+SUNPLUS WATCHDOG DRIVER
+M:	Xiantao Hu <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/watchdog/sunplus_wdt.c
+
 SUPERH
 M:	Yoshinori Sato <[email protected]>
 M:	Rich Felker <[email protected]>
drivers/watchdog/Kconfig +11 -0
index bf59faeb3..1a95df8ed 100644
@@ -990,6 +990,17 @@ config MSC313E_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called msc313e_wdt.
 
+config SUNPLUS_WATCHDOG
+	tristate "Sunplus watchdog support"
+	depends on ARCH_SUNPLUS || COMPILE_TEST
+	select WATCHDOG_CORE
+	help
+	  Say Y here to include support for the watchdog timer
+	  in Sunplus SoCs.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called sunplus_wdt.
+
 # X86 (i386 + ia64 + x86_64) Architecture
 
 config ACQUIRE_WDT
drivers/watchdog/Makefile +1 -0
index 1bd2d6f37..d6a9e4d0e 100644
@@ -94,6 +94,7 @@ obj-$(CONFIG_PM8916_WATCHDOG) += pm8916_wdt.o
 obj-$(CONFIG_ARM_SMC_WATCHDOG) += arm_smc_wdt.o
 obj-$(CONFIG_VISCONTI_WATCHDOG) += visconti_wdt.o
 obj-$(CONFIG_MSC313E_WATCHDOG) += msc313e_wdt.o
+obj-$(CONFIG_SUNPLUS_WATCHDOG) += sunplus_wdt.o
 
 # X86 (i386 + ia64 + x86_64) Architecture
 obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
drivers/watchdog/sunplus_wdt.c new file +297 -0

297 lines not on this page · raw message

Signature · 1 line
2.33.1
maintainer
#2 lore raw

Re: [PATCH 1/2] watchdog: Add watchdog driver for Sunplus SP7021

Quoted 110 lines · Xiantao Hu

Sunplus SP7021 requires watchdog timer support.
Add watchdog driver to enable this.

---
  MAINTAINERS                    |   6 +
  drivers/watchdog/Kconfig       |  11 ++
  drivers/watchdog/Makefile      |   1 +
  drivers/watchdog/sunplus_wdt.c | 297 +++++++++++++++++++++++++++++++++
  4 files changed, 315 insertions(+)

create mode 100644 drivers/watchdog/sunplus_wdt.c

MAINTAINERS +6 -0
index e0bca0de0..f6a328772 100644
@@ -17933,6 +17933,12 @@ L:	[email protected]
  S:	Maintained
  F:	drivers/net/ethernet/dlink/sundance.c
 
+SUNPLUS WATCHDOG DRIVER
+M:	Xiantao Hu <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/watchdog/sunplus_wdt.c
+
  SUPERH
  M:	Yoshinori Sato <[email protected]>
  M:	Rich Felker <[email protected]>
drivers/watchdog/Kconfig +11 -0
index bf59faeb3..1a95df8ed 100644
@@ -990,6 +990,17 @@ config MSC313E_WATCHDOG
  	  To compile this driver as a module, choose M here: the
  	  module will be called msc313e_wdt.
 
+config SUNPLUS_WATCHDOG
+	tristate "Sunplus watchdog support"
+	depends on ARCH_SUNPLUS || COMPILE_TEST
+	select WATCHDOG_CORE
+	help
+	  Say Y here to include support for the watchdog timer
+	  in Sunplus SoCs.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called sunplus_wdt.
+
  # X86 (i386 + ia64 + x86_64) Architecture
 
  config ACQUIRE_WDT
drivers/watchdog/Makefile +1 -0
index 1bd2d6f37..d6a9e4d0e 100644
@@ -94,6 +94,7 @@ obj-$(CONFIG_PM8916_WATCHDOG) += pm8916_wdt.o
  obj-$(CONFIG_ARM_SMC_WATCHDOG) += arm_smc_wdt.o
  obj-$(CONFIG_VISCONTI_WATCHDOG) += visconti_wdt.o
  obj-$(CONFIG_MSC313E_WATCHDOG) += msc313e_wdt.o
+obj-$(CONFIG_SUNPLUS_WATCHDOG) += sunplus_wdt.o
 
  # X86 (i386 + ia64 + x86_64) Architecture
  obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
drivers/watchdog/sunplus_wdt.c new file +41 -0
new file mode 100644
index 000000000..27f22c518
@@ -0,0 +1,297 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * sunplus Watchdog Driver
+ *
+ * Copyright (C) 2021 Sunplus Technology Co., Ltd.
+ *
+ */
+
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/platform_device.h>
+#include <linux/reset.h>
+#include <linux/watchdog.h>
+
+#define WDT_CTRL                0x00
+#define WDT_CNT                 0x04
+
+#define WDT_STOP				0x3877
+#define WDT_RESUME				0x4A4B
+#define WDT_CLRIRQ				0x7482
+#define WDT_UNLOCK				0xAB00
+#define WDT_LOCK				0xAB01
+#define WDT_CONMAX				0xDEAF
+
+#define RBUS_WDT_RST        BIT(1)
+#define STC_WDT_RST         BIT(4)
+
+#define MASK_SET(mask)		((mask) | (mask << 16))
+
+#define SP_WDT_MAX_TIMEOUT		11
+#define SP_WDT_MIN_TIMEOUT		1
+
+#define STC_CLK				90000
+
+#define DEVICE_NAME		"sunplus-wdt"
+
+static unsigned int timeout;
+module_param(timeout, int, 0);
+MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds");

drivers/watchdog/sunplus_wdt.c line 51

Quoted 10 lines
drivers/watchdog/sunplus_wdt.c new file +10 -0
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+			__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct sp_wdt_priv {
+	struct watchdog_device wdev;
+	void __iomem *base;
+	void __iomem *miscellaneous;

Please find a better name for this variable. Also, unless I am missing something, it is only used in the init function. That means it can be passed to that function as parameter and doesn't need to be stored in sp_wdt_priv.

Quoted 31 lines
drivers/watchdog/sunplus_wdt.c new file +31 -0
+	struct clk *clk;
+	struct reset_control *rstc;
+};
+
+static int sp_wdt_restart(struct watchdog_device *wdev,
+			       unsigned long action, void *data)
+{
+	struct sp_wdt_priv *priv = watchdog_get_drvdata(wdev);
+	void __iomem *base;
+
+	base = priv->base;
+	writel(WDT_STOP, base + WDT_CTRL);
+	writel(WDT_UNLOCK, base + WDT_CTRL);
+	writel(0x0001, base + WDT_CNT);
+	writel(WDT_RESUME, base + WDT_CTRL);
+
+	return 0;
+}
+
+/* TIMEOUT_MAX = ffff0/90kHz =11.65,so longer than 11 seconds will time out */
+static int sp_wdt_ping(struct watchdog_device *wdev)
+{
+	struct sp_wdt_priv *priv = watchdog_get_drvdata(wdev);
+	void __iomem *base = priv->base;
+	u32 count;
+
+	writel(WDT_STOP, base + WDT_CTRL);
+	writel(WDT_UNLOCK, base + WDT_CTRL);
+	/* tiemrw_cnt[3:0]cant be write,only [19:4] can be write. */
+	count = (wdev->timeout * STC_CLK) >> 4;
+	writel(count, base + WDT_CNT);

drivers/watchdog/sunplus_wdt.c line 92

Quoted 10 lines
drivers/watchdog/sunplus_wdt.c new file +10 -0
+	writel(WDT_RESUME, base + WDT_CTRL);
+
+	return 0;
+}
+
+static int sp_wdt_set_timeout(struct watchdog_device *wdev,
+				   unsigned int timeout)
+{
+	wdev->timeout = timeout;
+

I would assume this also needs to set the new timeout in HW if the watchdog is running, or the watchdog could time out before userspace sends another ping.

Quoted 8 lines
drivers/watchdog/sunplus_wdt.c new file +8 -0
+	return 0;
+}
+
+static int sp_wdt_stop(struct watchdog_device *wdev)
+{
+	struct sp_wdt_priv *priv = watchdog_get_drvdata(wdev);
+	void __iomem *base = priv->base;
+

drivers/watchdog/sunplus_wdt.c line 110

Quoted 10 lines
drivers/watchdog/sunplus_wdt.c new file +10 -0
+	writel(WDT_STOP, base + WDT_CTRL);
+
+	return 0;
+}
+
+static int sp_wdt_start(struct watchdog_device *wdev)
+{
+	int ret;
+
+	ret = sp_wdt_set_timeout(wdev, wdev->timeout);

That function never returns an error, so checking for it is pointless here.

Quoted 15 lines
drivers/watchdog/sunplus_wdt.c new file +15 -0
+	if (ret < 0)
+		return ret;
+
+	sp_wdt_ping(wdev);
+
+	return 0;
+}
+
+static unsigned int sp_wdt_get_timeleft(struct watchdog_device *wdev)
+{
+	struct sp_wdt_priv *priv = watchdog_get_drvdata(wdev);
+	void __iomem *base = priv->base;
+	u32 val;
+
+	val = readl(base + WDT_CNT);

drivers/watchdog/sunplus_wdt.c line 135

Quoted 10 lines
drivers/watchdog/sunplus_wdt.c new file +10 -0
+	val &= 0xffff;
+	val = val << 4;
+
+	return val;
+}
+
+/*
+ * 1.We need to reset watchdog flag(clear watchdog interrupt) here
+ * because watchdog timer driver does not have an interrupt handler,
+ * and before enalbe STC and RBUS watchdog timeout. Otherwise,

enable

drivers/watchdog/sunplus_wdt.c line 138

Quoted 3 lines
drivers/watchdog/sunplus_wdt.c new file +3 -0
+ * the intr is always in the triggered state.
+ * 2.enable STC and RBUS watchdog timeout trigger.
+ * 3.watchdog conuter is running, need to be stopped.

counter

Quoted 61 lines
drivers/watchdog/sunplus_wdt.c new file +61 -0
+ */
+static int sp_wdt_hw_init(struct watchdog_device *wdev)
+{
+	struct sp_wdt_priv *priv = watchdog_get_drvdata(wdev);
+	void __iomem *base = priv->base;
+	void __iomem *miscellaneous = priv->miscellaneous;
+	u32 val;
+
+	writel(WDT_CLRIRQ, base + WDT_CTRL);
+	val = readl(miscellaneous);
+	val |= MASK_SET(STC_WDT_RST);
+	val |= MASK_SET(RBUS_WDT_RST);
+	writel(val, miscellaneous);
+
+	sp_wdt_stop(wdev);
+
+	return 0;
+}
+
+static const struct watchdog_info sp_wdt_info = {
+	.identity = DEVICE_NAME,
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+};
+
+static const struct watchdog_ops sp_wdt_ops = {
+	.owner = THIS_MODULE,
+	.start = sp_wdt_start,
+	.stop = sp_wdt_stop,
+	.ping = sp_wdt_ping,
+	.set_timeout = sp_wdt_set_timeout,
+	.get_timeleft = sp_wdt_get_timeleft,
+	.restart = sp_wdt_restart,
+};
+
+static int sp_wdt_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct sp_wdt_priv *priv;
+	struct resource *wdt_res;
+	struct clk *clk;
+	int err;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(priv->clk)) {
+		dev_err(dev, "Can't find clock source\n");
+		return PTR_ERR(priv->clk);
+	}
+
+	err = clk_prepare_enable(clk);
+	if (err) {
+		dev_err(dev, "Clock can't be enabled correctly\n");
+		return err;
+	}
+
+	priv->rstc = devm_reset_control_get_exclusive(dev, NULL);
+	if (!IS_ERR(priv->rstc))
+		reset_control_deassert(priv->rstc);

drivers/watchdog/sunplus_wdt.c line 209

Quoted 10 lines
drivers/watchdog/sunplus_wdt.c new file +10 -0
+
+	platform_set_drvdata(pdev, priv);
+
+	priv->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(priv->base))
+		return PTR_ERR(priv->base);
+
+	wdt_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+	priv->miscellaneous =
+	    devm_ioremap(dev, wdt_res->start, resource_size(wdt_res));

Why not use devm_ioremap_resource() ? Or, for that matter, devm_platform_ioremap_resource() like above ?

drivers/watchdog/sunplus_wdt.c line 217

Quoted 8 lines
drivers/watchdog/sunplus_wdt.c new file +8 -0
+	if (IS_ERR(priv->miscellaneous))
+		return PTR_ERR(priv->miscellaneous);
+
+	priv->wdev.info = &sp_wdt_info;
+	priv->wdev.ops = &sp_wdt_ops;
+	priv->wdev.timeout = SP_WDT_MAX_TIMEOUT;
+	priv->wdev.max_timeout = SP_WDT_MAX_TIMEOUT;
+	priv->wdev.min_timeout = SP_WDT_MIN_TIMEOUT;

THis should really use max_hw_heartbeat_ms to let the core ping the watchdog if larger timeouts are desired.

drivers/watchdog/sunplus_wdt.c line 227

Quoted 10 lines
drivers/watchdog/sunplus_wdt.c new file +10 -0
+	priv->wdev.parent = dev;
+
+	watchdog_set_drvdata(&priv->wdev, priv);
+	sp_wdt_hw_init(&priv->wdev);
+
+	watchdog_init_timeout(&priv->wdev, timeout, dev);
+	watchdog_set_nowayout(&priv->wdev, nowayout);
+	watchdog_stop_on_reboot(&priv->wdev);
+
+	err = devm_watchdog_register_device(dev, &priv->wdev);

Since you call watchdog_unregister_device() below you can not use the devm_ function here.

drivers/watchdog/sunplus_wdt.c line 228

Quoted 1 line
drivers/watchdog/sunplus_wdt.c new file +1 -0
+	if (unlikely(err))

This is not time critical. Drop the unlikely.

Quoted 36 lines
drivers/watchdog/sunplus_wdt.c new file +36 -0
+		return err;
+
+	dev_info(dev, "Watchdog enabled (timeout=%d sec%s.)\n",
+		 priv->wdev.timeout, nowayout ? ", nowayout" : "");
+
+	return 0;
+}
+
+static int sp_wdt_remove(struct platform_device *pdev)
+{
+	struct sp_wdt_priv *priv = platform_get_drvdata(pdev);
+
+	watchdog_unregister_device(&priv->wdev);
+
+	reset_control_assert(priv->rstc);
+	clk_disable_unprepare(priv->clk);
+
+	return 0;
+}
+
+static const struct of_device_id sp_wdt_of_match[] = {
+	{.compatible = "sunplus,sp7021-wdt", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, sp_wdt_of_match);
+
+static int __maybe_unused sp_wdt_suspend(struct device *dev)
+{
+	struct sp_wdt_priv *priv = dev_get_drvdata(dev);
+
+	if (watchdog_active(&priv->wdev))
+		sp_wdt_stop(&priv->wdev);
+
+	reset_control_assert(priv->rstc);
+	clk_disable_unprepare(priv->clk);
+

drivers/watchdog/sunplus_wdt.c line 274

Quoted 10 lines
drivers/watchdog/sunplus_wdt.c new file +10 -0
+	return 0;
+}
+
+static int __maybe_unused sp_wdt_resume(struct device *dev)
+{
+	struct sp_wdt_priv *priv = dev_get_drvdata(dev);
+
+	if (watchdog_active(&priv->wdev))
+		sp_wdt_start(&priv->wdev);
+

Shouldn't the order be the opposite of the order in the suspend function ?

Quoted 24 lines
drivers/watchdog/sunplus_wdt.c new file +23 -0
+	reset_control_deassert(priv->rstc);
+	clk_prepare_enable(priv->clk);
+
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(sp_wdt_pm_ops, sp_wdt_suspend, sp_wdt_resume);
+
+static struct platform_driver sp_wdt_driver = {
+	.probe = sp_wdt_probe,
+	.remove = sp_wdt_remove,
+	.driver = {
+		   .name = DEVICE_NAME,
+		   .of_match_table = sp_wdt_of_match,
+		   .pm = &sp_wdt_pm_ops,
+	},
+};
+
+module_platform_driver(sp_wdt_driver);
+
+MODULE_AUTHOR("Xiantao Hu <[email protected]>");
+MODULE_DESCRIPTION("Sunplus Watchdog Timer Driver");
+MODULE_LICENSE("GPL v2");
author maintainer
#3 lore raw

RE: [PATCH 1/2] watchdog: Add watchdog driver for Sunplus SP7021

Hi, Guenter Roeck :

Thanks for your review. Sorry I was so focused on fixing code and I forgot to respond to the email. I modify the code as you comment and answer the question.

Thanks
Best Regards,
Xiantao Hu

Quoted 14 lines

-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: Friday, November 12, 2021 10:46 PM
To: xt.hu[胡先韬] <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Wells Lu 呂芳騰 <[email protected]>; qinjian[覃健] <[email protected]>
Subject: Re: [PATCH 1/2] watchdog: Add watchdog driver for Sunplus SP7021

Quoted 4 lines · Xiantao Hu

Sunplus SP7021 requires watchdog timer support.
Add watchdog driver to enable this.

...

Quoted 10 lines

drivers/watchdog/sunplus_wdt.c line 51

Quoted 4 lines
drivers/watchdog/sunplus_wdt.c new file +4 -0
+struct sp_wdt_priv {
+	struct watchdog_device wdev;
+	void __iomem *base;
+	void __iomem *miscellaneous;

Please find a better name for this variable. Also, unless I am missing something, it is only used in the init function. That means it can be passed to that function as parameter and doesn't need to be stored in sp_wdt_priv.

I will remove the miscellaneous from sp_wdt_priv and pass to that function as parameter.

Quoted 3 lines
Quoted 3 lines
drivers/watchdog/sunplus_wdt.c new file +3 -0
+	struct clk *clk;
+	struct reset_control *rstc;
+};

...

Quoted 10 lines

drivers/watchdog/sunplus_wdt.c line 92

Quoted 5 lines
drivers/watchdog/sunplus_wdt.c new file +5 -0
+static int sp_wdt_set_timeout(struct watchdog_device *wdev,
+				   unsigned int timeout)
+{
+	wdev->timeout = timeout;
+

I would assume this also needs to set the new timeout in HW if the watchdog is running, or the watchdog could time out before userspace sends another ping.

I will call the ping() after assigning timeout.

Quoted 3 lines
Quoted 3 lines
drivers/watchdog/sunplus_wdt.c new file +3 -0
+	return 0;
+}
+

...

Quoted 10 lines

drivers/watchdog/sunplus_wdt.c line 110

Quoted 6 lines
drivers/watchdog/sunplus_wdt.c new file +6 -0
+
+static int sp_wdt_start(struct watchdog_device *wdev)
+{
+	int ret;
+
+	ret = sp_wdt_set_timeout(wdev, wdev->timeout);

That function never returns an error, so checking for it is pointless here.

I will remove the variable ret.

Quoted 3 lines
Quoted 3 lines
drivers/watchdog/sunplus_wdt.c new file +3 -0
+	if (ret < 0)
+		return ret;
+

...

Quoted 7 lines
Quoted 4 lines

+/*
+ * 1.We need to reset watchdog flag(clear watchdog interrupt) here
+ * because watchdog timer driver does not have an interrupt handler,
+ * and before enalbe STC and RBUS watchdog timeout. Otherwise,

enable

I will fix it.

Quoted 6 lines
Quoted 3 lines

+ * the intr is always in the triggered state.
+ * 2.enable STC and RBUS watchdog timeout trigger.
+ * 3.watchdog conuter is running, need to be stopped.

counter

I will fix it.

Quoted 1 line
Quoted 1 line

+ */

...

Quoted 8 lines

drivers/watchdog/sunplus_wdt.c line 209

Quoted 4 lines
drivers/watchdog/sunplus_wdt.c new file +4 -0
+
+	wdt_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+	priv->miscellaneous =
+	    devm_ioremap(dev, wdt_res->start, resource_size(wdt_res));

Why not use devm_ioremap_resource() ? Or, for that matter, devm_platform_ioremap_resource() like above ?

The function of this register is miscellaneous. The register accessed here shared by multiple drivers. Use the function of devm_platform_ioremap_resource() which internally call request_mem_region() causes an error. So I handle it in this way. Any better ways?

Quoted 12 lines

drivers/watchdog/sunplus_wdt.c line 217

Quoted 8 lines
drivers/watchdog/sunplus_wdt.c new file +8 -0
+	if (IS_ERR(priv->miscellaneous))
+		return PTR_ERR(priv->miscellaneous);
+
+	priv->wdev.info = &sp_wdt_info;
+	priv->wdev.ops = &sp_wdt_ops;
+	priv->wdev.timeout = SP_WDT_MAX_TIMEOUT;
+	priv->wdev.max_timeout = SP_WDT_MAX_TIMEOUT;
+	priv->wdev.min_timeout = SP_WDT_MIN_TIMEOUT;

THis should really use max_hw_heartbeat_ms to let the core ping the watchdog if larger timeouts are desired.

I will add the max_hw_heartbeat_ms and modify the
ping ().

Quoted 5 lines
Quoted 5 lines
drivers/watchdog/sunplus_wdt.c new file +5 -0
+	priv->wdev.parent = dev;
+
+	watchdog_set_drvdata(&priv->wdev, priv);
+	sp_wdt_hw_init(&priv->wdev);
+
Quoted 9 lines

drivers/watchdog/sunplus_wdt.c line 227

Quoted 5 lines
drivers/watchdog/sunplus_wdt.c new file +5 -0
+	watchdog_init_timeout(&priv->wdev, timeout, dev);
+	watchdog_set_nowayout(&priv->wdev, nowayout);
+	watchdog_stop_on_reboot(&priv->wdev);
+
+	err = devm_watchdog_register_device(dev, &priv->wdev);

Since you call watchdog_unregister_device() below you can not use the devm_ function here.

I will drop the function remove() and not call watchdog_unregister_device() . Use the devm_add_action_or_reset() add reset_control_assert() and clk_disable_unprepare().

Quoted 4 lines

drivers/watchdog/sunplus_wdt.c line 228

Quoted 1 line
drivers/watchdog/sunplus_wdt.c new file +1 -0
+	if (unlikely(err))

This is not time critical. Drop the unlikely.

I will fix it.

Quoted 20 lines
Quoted 20 lines
drivers/watchdog/sunplus_wdt.c new file +20 -0
+		return err;
+
+	dev_info(dev, "Watchdog enabled (timeout=%d sec%s.)\n",
+		 priv->wdev.timeout, nowayout ? ", nowayout" : "");
+
+	return 0;
+}
+
+static int sp_wdt_remove(struct platform_device *pdev)
+{
+	struct sp_wdt_priv *priv = platform_get_drvdata(pdev);
+
+	watchdog_unregister_device(&priv->wdev);
+
+	reset_control_assert(priv->rstc);
+	clk_disable_unprepare(priv->clk);
+
+	return 0;
+}
+

...

Quoted 10 lines

drivers/watchdog/sunplus_wdt.c line 274

Quoted 8 lines
drivers/watchdog/sunplus_wdt.c new file +8 -0
+
+static int __maybe_unused sp_wdt_resume(struct device *dev)
+{
+	struct sp_wdt_priv *priv = dev_get_drvdata(dev);
+
+	if (watchdog_active(&priv->wdev))
+		sp_wdt_start(&priv->wdev);
+

Shouldn't the order be the opposite of the order in the suspend function ?

I will fix it.

Quoted 6 lines
Quoted 6 lines
drivers/watchdog/sunplus_wdt.c new file +5 -0
+	reset_control_deassert(priv->rstc);
+	clk_prepare_enable(priv->clk);
+
+	return 0;
+}

...

Quoted 1 line
Quoted 1 line
#4 lore raw

Re: [PATCH 1/2] watchdog: Add watchdog driver for Sunplus SP7021

In reply to Xiantao Hu
I love your patch! Perhaps something to improve:

Hi Xiantao,

I love your patch! Perhaps something to improve:

[auto build test WARNING on pza/reset/next]
[also build test WARNING on robh/for-next linux/master linus/master v5.16-rc1 next-20211118] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Xiantao-Hu/Add-watchdog-driver-for-Sunplus-SP7021-SoC/20211112-191201
base:   https://git.pengutronix.de/git/pza/linux reset/next
config: arm64-randconfig-r023-20211115 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project fbe72e41b99dc7994daac300d208a955be3e4a0a)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/eac808eeed4a851ca5cfef12adefd6df199f62c2
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Xiantao-Hu/Add-watchdog-driver-for-Sunplus-SP7021-SoC/20211112-191201 git checkout eac808eeed4a851ca5cfef12adefd6df199f62c2
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=arm64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/watchdog/sunplus_wdt.c:191:27: warning: variable 'clk' is uninitialized when used here [-Wuninitialized]
           err = clk_prepare_enable(clk);
                                    ^~~
   drivers/watchdog/sunplus_wdt.c:178:17: note: initialize the variable 'clk' to silence this warning
           struct clk *clk;
                          ^
                           = NULL

1 warning generated.

vim +/clk +191 drivers/watchdog/sunplus_wdt.c

172
173 static int sp_wdt_probe(struct platform_device *pdev)
174 {
175 struct device *dev = &pdev->dev;
176 struct sp_wdt_priv *priv;
177 struct resource *wdt_res;
178 struct clk *clk;
179 int err;
180
181 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
182 if (!priv)
183 return -ENOMEM;
184
185 priv->clk = devm_clk_get(dev, NULL);
186 if (IS_ERR(priv->clk)) {
187 dev_err(dev, "Can't find clock source\n");
188 return PTR_ERR(priv->clk);
189 }
190

 > 191		err = clk_prepare_enable(clk);

192 if (err) {
193 dev_err(dev, "Clock can't be enabled correctly\n");
194 return err;
195 }
196
197 priv->rstc = devm_reset_control_get_exclusive(dev, NULL);
198 if (!IS_ERR(priv->rstc))
199 reset_control_deassert(priv->rstc);
200
201 platform_set_drvdata(pdev, priv);
202
203 priv->base = devm_platform_ioremap_resource(pdev, 0);
204 if (IS_ERR(priv->base))
205 return PTR_ERR(priv->base);
206
207 wdt_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
208 priv->miscellaneous =
209 devm_ioremap(dev, wdt_res->start, resource_size(wdt_res));
210 if (IS_ERR(priv->miscellaneous))
211 return PTR_ERR(priv->miscellaneous);
212
213 priv->wdev.info = &sp_wdt_info;
214 priv->wdev.ops = &sp_wdt_ops;
215 priv->wdev.timeout = SP_WDT_MAX_TIMEOUT;
216 priv->wdev.max_timeout = SP_WDT_MAX_TIMEOUT;
217 priv->wdev.min_timeout = SP_WDT_MIN_TIMEOUT;
218 priv->wdev.parent = dev;
219
220 watchdog_set_drvdata(&priv->wdev, priv);
221 sp_wdt_hw_init(&priv->wdev);
222
223 watchdog_init_timeout(&priv->wdev, timeout, dev);
224 watchdog_set_nowayout(&priv->wdev, nowayout);
225 watchdog_stop_on_reboot(&priv->wdev);
226
227 err = devm_watchdog_register_device(dev, &priv->wdev);
228 if (unlikely(err))
229 return err;
230
231 dev_info(dev, "Watchdog enabled (timeout=%d sec%s.)\n",
232 priv->wdev.timeout, nowayout ? ", nowayout" : "");
233
234 return 0;
235 }
236

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author maintainer
#5 lore raw

PATCH 2/2 dt-bindings: watchdog: Add Sunplus SP7021 WDT devicetree bindings documentation

In reply to Xiantao Hu

This adds the documentation for the devicetree bindings of the Sunplus SP7021 watchdog driver, found from SP7021 SoCs and newer.

---
 .../bindings/watchdog/sunplus,sp7021-wdt.yaml | 47 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 48 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml
Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml new file +47 -0
new file mode 100644
index 000000000..bb728f298
@@ -0,0 +1,47 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/watchdog/sunplus,sp7021-wdt.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus SoCs Watchdog Device Tree Bindings
+
+maintainers:
+  - XianTao Hu <[email protected]>
+
+allOf:
+  - $ref: watchdog.yaml#
+
+properties:
+  compatible:
+    const: sunplus,sp7021-wdt
+
+  reg:
+    items:
+      - description: Base address and length of the watchdog registers
+      - description: Base address and length of the miscellaneous control registers
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - resets
+
+additionalProperties: false
+
+examples:
+  - |
+    watchdog: watchdog@9c000630 {
+        compatible = "sunplus,sp7021-wdt";
+        reg = <0x9c000630 0x08>, <0x9C000274 0x04>;
+        clocks = <&clkc 0x24>;
+        resets = <&rstc 0x14>;
+    };
+...
MAINTAINERS +1 -0
index f6a328772..d51f0cb1a 100644
@@ -17937,6 +17937,7 @@ SUNPLUS WATCHDOG DRIVER
 M:	Xiantao Hu <[email protected]>
 L:	[email protected]
 S:	Maintained
+F:	Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml
 F:	drivers/watchdog/sunplus_wdt.c
 
 SUPERH
Signature · 1 line
2.33.1
author maintainer
#6 lore raw

v2 cover Add watchdog driver for Sunplus SP7021 SoC

In reply to Xiantao Hu

This is a patch series for watchdog driver for Sunplus SP7021 SoC.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html

Xiantao Hu (2):
watchdog: Add watchdog driver for Sunplus SP7021
dt-bindings: watchdog: Add Sunplus SP7021 WDT devicetree bindings
documentation

 .../bindings/watchdog/sunplus,sp7021-wdt.yaml |  47 +++
 MAINTAINERS                                   |   7 +
 drivers/watchdog/Kconfig                      |  11 +
 drivers/watchdog/Makefile                     |   1 +
 drivers/watchdog/sunplus_wdt.c                | 322 ++++++++++++++++++
 5 files changed, 388 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml
 create mode 100644 drivers/watchdog/sunplus_wdt.c
Signature · 1 line
2.33.1
author maintainer
#7 lore raw

PATCH v2 1/2 watchdog: Add watchdog driver for Sunplus SP7021

Sunplus SP7021 requires watchdog timer support.
Add watchdog driver to enable this.

---
Changes in v2:
- Addressed all comments from Mr. Guenter Roeck
- Drop the remove()

 MAINTAINERS                    |   6 +
 drivers/watchdog/Kconfig       |  11 ++
 drivers/watchdog/Makefile      |   1 +
 drivers/watchdog/sunplus_wdt.c | 322 +++++++++++++++++++++++++++++++++
 4 files changed, 340 insertions(+)
 create mode 100644 drivers/watchdog/sunplus_wdt.c
MAINTAINERS +6 -0
index e0bca0de0..f6a328772 100644
@@ -17933,6 +17933,12 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/net/ethernet/dlink/sundance.c
 
+SUNPLUS WATCHDOG DRIVER
+M:	Xiantao Hu <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/watchdog/sunplus_wdt.c
+
 SUPERH
 M:	Yoshinori Sato <[email protected]>
 M:	Rich Felker <[email protected]>
drivers/watchdog/Kconfig +11 -0
index bf59faeb3..1a95df8ed 100644
@@ -990,6 +990,17 @@ config MSC313E_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called msc313e_wdt.
 
+config SUNPLUS_WATCHDOG
+	tristate "Sunplus watchdog support"
+	depends on ARCH_SUNPLUS || COMPILE_TEST
+	select WATCHDOG_CORE
+	help
+	  Say Y here to include support for the watchdog timer
+	  in Sunplus SoCs.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called sunplus_wdt.
+
 # X86 (i386 + ia64 + x86_64) Architecture
 
 config ACQUIRE_WDT
drivers/watchdog/Makefile +1 -0
index 1bd2d6f37..d6a9e4d0e 100644
@@ -94,6 +94,7 @@ obj-$(CONFIG_PM8916_WATCHDOG) += pm8916_wdt.o
 obj-$(CONFIG_ARM_SMC_WATCHDOG) += arm_smc_wdt.o
 obj-$(CONFIG_VISCONTI_WATCHDOG) += visconti_wdt.o
 obj-$(CONFIG_MSC313E_WATCHDOG) += msc313e_wdt.o
+obj-$(CONFIG_SUNPLUS_WATCHDOG) += sunplus_wdt.o
 
 # X86 (i386 + ia64 + x86_64) Architecture
 obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
drivers/watchdog/sunplus_wdt.c new file +322 -0

322 lines not on this page · raw message

Signature · 1 line
2.33.1
maintainer
#8 lore raw

Re: [PATCH v2 1/2] watchdog: Add watchdog driver for Sunplus SP7021

drivers/watchdog/sunplus_wdt.c line 234

Quoted 12 lines · Xiantao Hu

Sunplus SP7021 requires watchdog timer support.
Add watchdog driver to enable this.

---

drivers/watchdog/sunplus_wdt.c new file +7 -0
+
+	priv->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(priv->base))
+		return PTR_ERR(priv->base);
+
+	/* The registers accessed here shared by multiple drivers. */
+	wdt_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);

This is unusual. Why would other drivers access WDT_CTRL and WDT_CNT registers, and how is it ensured that the other drivers do not interfer with the accesses by this driver ?

Normally such a resource would be shared through a parent driver with appropriate access functions to ensure that accesses are synchronized.

Thanks,
Guenter

author maintainer
#9 lore raw

RE: [PATCH v2 1/2] watchdog: Add watchdog driver for Sunplus SP7021

Hi
Thanks for your review. I explain this in detail below the comment.

Best Regards,
Xiantao

Quoted 26 lines

-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: Wednesday, November 24, 2021 10:25 PM
To: xt.hu[胡先韬] <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wells Lu 呂芳騰 <[email protected]>; qinjian[覃健] <[email protected]>
Subject: Re: [PATCH v2 1/2] watchdog: Add watchdog driver for Sunplus SP7021

drivers/watchdog/sunplus_wdt.c line 234

Quoted 12 lines · Xiantao Hu

Sunplus SP7021 requires watchdog timer support.
Add watchdog driver to enable this.

---

drivers/watchdog/sunplus_wdt.c new file +7 -0
+
+	priv->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(priv->base))
+		return PTR_ERR(priv->base);
+
+	/* The registers accessed here shared by multiple drivers. */
+	wdt_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);

This is unusual. Why would other drivers access WDT_CTRL and WDT_CNT registers, and how is it ensured that the other drivers do not interfer with the accesses by this driver ?

Quoted 3 lines

Normally such a resource would be shared through a parent driver with appropriate access functions to ensure that accesses are synchronized.

The register used by this driver consists of two parts. The first part which contains WDT_CTRL and WDT_CNT registers is exclusive by watchdog.
In specially, the second part is belong to a multifunctional register group which control IP and bus. Refer to register manual below:
-------------------------------------------------------------------------------------------------------------------------------------------------
MO1_STC_WDG_RST_EN 4 RW STC Watchdog Timeout Trigger System Reset Enable
0: STC watchdog 2 timeout will not trigger system reset(default) 1: STC watchdog 2 timeout will trigger system reset
MO1_RI_WDG_RST_EN 1 RW RBUS Watchdog Timeout Trigger System Reset Enable
0: RBUS watchdog timeout will not trigger system reset(default) 1: RBUS watchdog timeout will trigger system reset
MO1_TIMER_STAND_BY_EN 0 RW Timer Standby Mode Enable
0: Disable (default)
1: Enable Active high to enter timer standby mode,
default not in standby mode
-------------------------------------------------------------------------------------------------------------------------------------------------
You can see that in addition to the bits for watchdog there are bit fields for other modules.
I use this register bit4 and bit1. Default value is 0 that watchdog internal interrupt signal can't trigger system and RBUS reset. I need set 1 when watchdog probe. Early I implement the operation in arch/arm/mach-sunplus/sp7021.c and configure by macro. But in arch/arm64, directory mach-XXX is removed.
So I solve in this way. Any better way?

Quoted 2 lines

Thanks,
Guenter

maintainer
#10 lore raw

Re: [PATCH v2 1/2] watchdog: Add watchdog driver for Sunplus SP7021

Quoted 48 lines · xt.hu[胡先韬]

Hi
Thanks for your review. I explain this in detail below the comment.

Best Regards,
Xiantao

Quoted 26 lines

-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: Wednesday, November 24, 2021 10:25 PM
To: xt.hu[胡先韬] <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wells Lu 呂芳騰 <[email protected]>; qinjian[覃健] <[email protected]>
Subject: Re: [PATCH v2 1/2] watchdog: Add watchdog driver for Sunplus SP7021

drivers/watchdog/sunplus_wdt.c line 234

Quoted 12 lines · Xiantao Hu

Sunplus SP7021 requires watchdog timer support.
Add watchdog driver to enable this.

---

drivers/watchdog/sunplus_wdt.c new file +7 -0
+
+	priv->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(priv->base))
+		return PTR_ERR(priv->base);
+
+	/* The registers accessed here shared by multiple drivers. */
+	wdt_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);

This is unusual. Why would other drivers access WDT_CTRL and WDT_CNT registers, and how is it ensured that the other drivers do not interfer with the accesses by this driver ?

Quoted 3 lines

Normally such a resource would be shared through a parent driver with appropriate access functions to ensure that accesses are synchronized.

The register used by this driver consists of two parts. The first part which contains WDT_CTRL and WDT_CNT registers is exclusive by watchdog.
In specially, the second part is belong to a multifunctional register group which control IP and bus. Refer to register manual below:
-------------------------------------------------------------------------------------------------------------------------------------------------
MO1_STC_WDG_RST_EN 4 RW STC Watchdog Timeout Trigger System Reset Enable
0: STC watchdog 2 timeout will not trigger system reset(default) 1: STC watchdog 2 timeout will trigger system reset
MO1_RI_WDG_RST_EN 1 RW RBUS Watchdog Timeout Trigger System Reset Enable
0: RBUS watchdog timeout will not trigger system reset(default) 1: RBUS watchdog timeout will trigger system reset
MO1_TIMER_STAND_BY_EN 0 RW Timer Standby Mode Enable
0: Disable (default)

Quoted 9 lines

1: Enable Active high to enter timer standby mode,
default not in standby mode
-------------------------------------------------------------------------------------------------------------------------------------------------
You can see that in addition to the bits for watchdog there are bit fields for other modules.
I use this register bit4 and bit1. Default value is 0 that watchdog internal interrupt signal can't trigger system and RBUS reset. I need set 1 when watchdog probe. Early I implement the operation in arch/arm/mach-sunplus/sp7021.c and configure by macro. But in arch/arm64, directory mach-XXX is removed. So I solve in this way. Any better way?

If the register at 0x9C000274 is accessed by other drivers, accesses to it must be protected against each other to avoid race conditions. How to do that would be up to you.

Guenter

author maintainer
#11 lore raw

RE: [PATCH v2 1/2] watchdog: Add watchdog driver for Sunplus SP7021

Quoted 71 lines

-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: Thursday, November 25, 2021 12:26 PM
To: xt.hu[胡先韬] <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wells Lu 呂芳騰 <[email protected]>; qinjian[覃健] <[email protected]>
Subject: Re: [PATCH v2 1/2] watchdog: Add watchdog driver for Sunplus SP7021

Quoted 11 lines · xt.hu[胡先韬]

Hi
Thanks for your review. I explain this in detail below the comment.

Best Regards,
Xiantao

Quoted 6 lines

-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: Wednesday, November 24, 2021 10:25 PM
To: xt.hu[胡先韬] <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wells Lu 呂芳

騰

Quoted 20 lines
Quoted 20 lines

<[email protected]>; qinjian[覃健] <[email protected]>
Subject: Re: [PATCH v2 1/2] watchdog: Add watchdog driver for Sunplus SP7021

drivers/watchdog/sunplus_wdt.c line 234

Quoted 12 lines · Xiantao Hu

Sunplus SP7021 requires watchdog timer support.
Add watchdog driver to enable this.

---

drivers/watchdog/sunplus_wdt.c new file +7 -0
+
+	priv->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(priv->base))
+		return PTR_ERR(priv->base);
+
+	/* The registers accessed here shared by multiple drivers. */
+	wdt_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);

This is unusual. Why would other drivers access WDT_CTRL and WDT_CNT registers, and how is it ensured that the other drivers do not interfer with the accesses by this driver ?

Quoted 1 line
Quoted 1 line

Normally such a resource would be shared through a parent driver with appropriate access functions

to

Quoted 4 lines
Quoted 2 lines

ensure that accesses are synchronized.

The register used by this driver consists of two parts. The first part which contains WDT_CTRL and

WDT_CNT

Quoted 2 lines

registers is exclusive by watchdog.
In specially, the second part is belong to a multifunctional register group which control IP and bus.

Refer to

Quoted 4 lines

register manual below:
-------------------------------------------------------------------------------------------------------------------------------------------------
MO1_STC_WDG_RST_EN 4 RW STC Watchdog Timeout Trigger System Reset Enable
0: STC watchdog 2 timeout will not trigger system

reset(default)

Quoted 3 lines

1: STC watchdog 2 timeout will trigger system reset
MO1_RI_WDG_RST_EN 1 RW RBUS Watchdog Timeout Trigger System Reset Enable
0: RBUS watchdog timeout will not trigger system

reset(default)

Quoted 8 lines

1: RBUS watchdog timeout will trigger system reset
MO1_TIMER_STAND_BY_EN 0 RW Timer Standby Mode Enable
0: Disable (default)
1: Enable Active high to enter timer standby mode,
default not in standby mode
-------------------------------------------------------------------------------------------------------------------------------------------------
You can see that in addition to the bits for watchdog there are bit fields for other modules.
I use this register bit4 and bit1. Default value is 0 that watchdog internal interrupt signal can't trigger

system

Quoted 9 lines
Quoted 2 lines

and RBUS reset. I need set 1 when watchdog probe. Early I implement the operation in arch/arm/mach-sunplus/sp7021.c and configure by macro. But in arch/arm64, directory mach-XXX is

removed.

Quoted 2 lines

So I solve in this way. Any better way?

If the register at 0x9C000274 is accessed by other drivers, accesses to it must be protected against each other to avoid race conditions. How to do that would be up to you.

Hi Guenter,

From the perspective of software, 0x9C000274 is only accessed during driver probe. If the driver is build-in and only one core is running at kernel startup. There is no competition.
The only possibility of an error is to compile the driver into a module. In this case, the register at 0x9C000274 offer MASK_BITS[31:16] which write valid bit for each LSB 16 bits. Refer to the define in driver:
#define MASK_SET(mask) ((mask) | (mask << 16))
Even if both drivers access the register at the same time, the instructions are executed in order on the RBUS. So as long as the same bit in the same register is not accessed at the same time, no error will occur.

Best Regards,
Xiantao

Quoted 1 line

Guenter

maintainer
#12 lore raw

Re: [PATCH v2 1/2] watchdog: Add watchdog driver for Sunplus SP7021

Quoted 82 lines · xt.hu[胡先韬]
Quoted 71 lines

-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: Thursday, November 25, 2021 12:26 PM
To: xt.hu[胡先韬] <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wells Lu 呂芳騰 <[email protected]>; qinjian[覃健] <[email protected]>
Subject: Re: [PATCH v2 1/2] watchdog: Add watchdog driver for Sunplus SP7021

Quoted 11 lines · xt.hu[胡先韬]

Hi
Thanks for your review. I explain this in detail below the comment.

Best Regards,
Xiantao

Quoted 6 lines

-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: Wednesday, November 24, 2021 10:25 PM
To: xt.hu[胡先韬] <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wells Lu 呂芳

騰

Quoted 20 lines
Quoted 20 lines

<[email protected]>; qinjian[覃健] <[email protected]>
Subject: Re: [PATCH v2 1/2] watchdog: Add watchdog driver for Sunplus SP7021

drivers/watchdog/sunplus_wdt.c line 234

Quoted 12 lines · Xiantao Hu

Sunplus SP7021 requires watchdog timer support.
Add watchdog driver to enable this.

---

drivers/watchdog/sunplus_wdt.c new file +7 -0
+
+	priv->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(priv->base))
+		return PTR_ERR(priv->base);
+
+	/* The registers accessed here shared by multiple drivers. */
+	wdt_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);

This is unusual. Why would other drivers access WDT_CTRL and WDT_CNT registers, and how is it ensured that the other drivers do not interfer with the accesses by this driver ?

Quoted 1 line
Quoted 1 line

Normally such a resource would be shared through a parent driver with appropriate access functions

to

Quoted 4 lines
Quoted 2 lines

ensure that accesses are synchronized.

The register used by this driver consists of two parts. The first part which contains WDT_CTRL and

WDT_CNT

Quoted 2 lines

registers is exclusive by watchdog.
In specially, the second part is belong to a multifunctional register group which control IP and bus.

Refer to

Quoted 4 lines

register manual below:
-------------------------------------------------------------------------------------------------------------------------------------------------
MO1_STC_WDG_RST_EN 4 RW STC Watchdog Timeout Trigger System Reset Enable
0: STC watchdog 2 timeout will not trigger system

reset(default)

Quoted 3 lines

1: STC watchdog 2 timeout will trigger system reset
MO1_RI_WDG_RST_EN 1 RW RBUS Watchdog Timeout Trigger System Reset Enable
0: RBUS watchdog timeout will not trigger system

reset(default)

Quoted 8 lines

1: RBUS watchdog timeout will trigger system reset
MO1_TIMER_STAND_BY_EN 0 RW Timer Standby Mode Enable
0: Disable (default)
1: Enable Active high to enter timer standby mode,
default not in standby mode
-------------------------------------------------------------------------------------------------------------------------------------------------
You can see that in addition to the bits for watchdog there are bit fields for other modules.
I use this register bit4 and bit1. Default value is 0 that watchdog internal interrupt signal can't trigger

system

Quoted 9 lines
Quoted 2 lines

and RBUS reset. I need set 1 when watchdog probe. Early I implement the operation in arch/arm/mach-sunplus/sp7021.c and configure by macro. But in arch/arm64, directory mach-XXX is

removed.

Quoted 2 lines

So I solve in this way. Any better way?

If the register at 0x9C000274 is accessed by other drivers, accesses to it must be protected against each other to avoid race conditions. How to do that would be up to you.

Hi Guenter,

Quoted 11 lines

From the perspective of software, 0x9C000274 is only accessed during
driver probe. If the driver is build-in and only one core is running at kernel startup. There is no competition.
The only possibility of an error is to compile the driver into a module. In this case, the register at 0x9C000274 offer MASK_BITS[31:16] which write valid bit for each LSB 16 bits. Refer to the define in driver:
#define MASK_SET(mask) ((mask) | (mask << 16))
Even if both drivers access the register at the same time, the instructions are executed in order on the RBUS. So as long as the same bit in the same register is not accessed at the same time, no error will occur.

This is inherently risky and racy. I am sure there is a better way to solve this without risking race conditions, but I don't have time to analyze it further. The above rationale needs to be added in detail to the driver as comments, including references to all other drivers accessing the same register or memory space.

Guenter

author maintainer
#13 lore raw

PATCH v2 2/2 dt-bindings: watchdog: Add Sunplus SP7021 WDT devicetree bindings documentation

In reply to Xiantao Hu

This adds the documentation for the devicetree bindings of the Sunplus SP7021 watchdog driver, found from SP7021 SoCs and newer.

---
 .../bindings/watchdog/sunplus,sp7021-wdt.yaml | 47 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 48 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml
Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml new file +47 -0
new file mode 100644
index 000000000..bb728f298
@@ -0,0 +1,47 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/watchdog/sunplus,sp7021-wdt.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus SoCs Watchdog Device Tree Bindings
+
+maintainers:
+  - XianTao Hu <[email protected]>
+
+allOf:
+  - $ref: watchdog.yaml#
+
+properties:
+  compatible:
+    const: sunplus,sp7021-wdt
+
+  reg:
+    items:
+      - description: Base address and length of the watchdog registers
+      - description: Base address and length of the miscellaneous control registers
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - resets
+
+additionalProperties: false
+
+examples:
+  - |
+    watchdog: watchdog@9c000630 {
+        compatible = "sunplus,sp7021-wdt";
+        reg = <0x9c000630 0x08>, <0x9C000274 0x04>;
+        clocks = <&clkc 0x24>;
+        resets = <&rstc 0x14>;
+    };
+...
MAINTAINERS +1 -0
index f6a328772..d51f0cb1a 100644
@@ -17937,6 +17937,7 @@ SUNPLUS WATCHDOG DRIVER
 M:	Xiantao Hu <[email protected]>
 L:	[email protected]
 S:	Maintained
+F:	Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml
 F:	drivers/watchdog/sunplus_wdt.c
 
 SUPERH
Signature · 1 line
2.33.1
maintainer Reviewed-by on v2 2/2
#14 lore raw

Re: [PATCH v2 2/2] dt-bindings: watchdog: Add Sunplus SP7021 WDT devicetree bindings documentation

Quoted 10 lines · Xiantao Hu

This adds the documentation for the devicetree bindings of the Sunplus SP7021 watchdog driver, found from SP7021 SoCs and newer.

---
 .../bindings/watchdog/sunplus,sp7021-wdt.yaml | 47 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 48 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml
maintainer
#15 lore raw
In reply to Xiantao Hu
Quoted 6 lines · Xiantao Hu

This is a patch series for watchdog driver for Sunplus SP7021 SoC.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

Why are more and more people sending patches or patch series as reply to previous patches ? This all by ensures that patches get lost.

Is that promoted somewhere ?

Thanks,
Guenter

author maintainer
#16 lore raw

Hi Guenter,
This is my second submitting. I also refer to the format in others' emails. If the format is not correct, I will drop --in-reply-to when submit pathch next time.

Best Regards,
Xiantao

Quoted 24 lines

-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: Wednesday, November 24, 2021 10:18 PM
To: xt.hu[胡先韬] <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wells Lu 呂芳騰 <[email protected]>; qinjian[覃健] <[email protected]>
Subject: Re: [PATCH v2 0/2] Add watchdog driver for Sunplus SP7021 SoC

Quoted 6 lines · Xiantao Hu

This is a patch series for watchdog driver for Sunplus SP7021 SoC.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

Why are more and more people sending patches or patch series as reply to previous patches ? This all by ensures that patches get lost.

Is that promoted somewhere ?

Thanks,
Guenter