linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Alice Guo (OSS)" <alice.guo@oss.nxp.com>
To: wim@linux-watchdog.org, linux@roeck-us.net, shawnguo@kernel.org,
	s.hauer@pengutronix.de, festevam@gmail.com
Cc: kernel@pengutronix.de, linux-imx@nxp.com,
	linux-watchdog@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 7/7] watchdog: imx93: add watchdog timer on imx93
Date: Tue, 16 Aug 2022 12:36:43 +0800	[thread overview]
Message-ID: <20220816043643.26569-8-alice.guo@oss.nxp.com> (raw)
In-Reply-To: <20220816043643.26569-1-alice.guo@oss.nxp.com>

From: Alice Guo <alice.guo@nxp.com>

The WDOG clocks are sourced from lpo_clk, and lpo_clk is the fixed
32KHz. TOVAL contains the 16-bit value used to set the timeout period of
the watchdog. When the timeout period exceeds 2 seconds, the value
written to the TOVAL register is larger than 16-bit can represent.
Enabling watchdog prescaler can solve this problem.

Two points need to be aware of:
1. watchdog prescaler enables a fixed 256 pre-scaling of watchdog
counter reference clock
2. reconfiguration takes about 55ms on imx93

Reviewed-by: Jacky Bai <ping.bai@nxp.com>
Signed-off-by: Alice Guo <alice.guo@nxp.com>
---
 drivers/watchdog/imx7ulp_wdt.c | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/drivers/watchdog/imx7ulp_wdt.c b/drivers/watchdog/imx7ulp_wdt.c
index 58508f69d933..4694aa4b8cfb 100644
--- a/drivers/watchdog/imx7ulp_wdt.c
+++ b/drivers/watchdog/imx7ulp_wdt.c
@@ -9,6 +9,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/reboot.h>
 #include <linux/watchdog.h>
@@ -52,11 +53,17 @@ module_param(nowayout, bool, 0000);
 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
 		 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
 
+struct imx_wdt_hw_feature {
+	bool prescaler_enable;
+	u32 wdog_clock_rate;
+};
+
 struct imx7ulp_wdt_device {
 	struct watchdog_device wdd;
 	void __iomem *base;
 	struct clk *clk;
 	bool post_rcs_wait;
+	const struct imx_wdt_hw_feature *hw;
 };
 
 static int imx7ulp_wdt_wait_ulk(void __iomem *base)
@@ -179,7 +186,7 @@ static int imx7ulp_wdt_set_timeout(struct watchdog_device *wdog,
 				   unsigned int timeout)
 {
 	struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog);
-	u32 toval = WDOG_CLOCK_RATE * timeout;
+	u32 toval = wdt->hw->wdog_clock_rate * timeout;
 	u32 val;
 	int ret;
 	u32 loop = RETRY_MAX;
@@ -276,6 +283,9 @@ static int imx7ulp_wdt_init(struct imx7ulp_wdt_device *wdt, unsigned int timeout
 	int ret;
 	u32 loop = RETRY_MAX;
 
+	if (wdt->hw->prescaler_enable)
+		val |= WDOG_CS_PRES;
+
 	do {
 		ret = _imx7ulp_wdt_init(wdt, timeout, val);
 		toval = readl(wdt->base + WDOG_TOVAL);
@@ -346,7 +356,9 @@ static int imx7ulp_wdt_probe(struct platform_device *pdev)
 	watchdog_stop_on_reboot(wdog);
 	watchdog_stop_on_unregister(wdog);
 	watchdog_set_drvdata(wdog, imx7ulp_wdt);
-	ret = imx7ulp_wdt_init(imx7ulp_wdt, wdog->timeout * WDOG_CLOCK_RATE);
+
+	imx7ulp_wdt->hw = of_device_get_match_data(dev);
+	ret = imx7ulp_wdt_init(imx7ulp_wdt, wdog->timeout * imx7ulp_wdt->hw->wdog_clock_rate);
 	if (ret)
 		return ret;
 
@@ -368,7 +380,7 @@ static int __maybe_unused imx7ulp_wdt_suspend_noirq(struct device *dev)
 static int __maybe_unused imx7ulp_wdt_resume_noirq(struct device *dev)
 {
 	struct imx7ulp_wdt_device *imx7ulp_wdt = dev_get_drvdata(dev);
-	u32 timeout = imx7ulp_wdt->wdd.timeout * WDOG_CLOCK_RATE;
+	u32 timeout = imx7ulp_wdt->wdd.timeout * imx7ulp_wdt->hw->wdog_clock_rate;
 	int ret;
 
 	ret = clk_prepare_enable(imx7ulp_wdt->clk);
@@ -389,9 +401,20 @@ static const struct dev_pm_ops imx7ulp_wdt_pm_ops = {
 				      imx7ulp_wdt_resume_noirq)
 };
 
+static const struct imx_wdt_hw_feature imx7ulp_wdt_hw = {
+	.prescaler_enable = false,
+	.wdog_clock_rate = 1000,
+};
+
+static const struct imx_wdt_hw_feature imx93_wdt_hw = {
+	.prescaler_enable = true,
+	.wdog_clock_rate = 125,
+};
+
 static const struct of_device_id imx7ulp_wdt_dt_ids[] = {
-	{ .compatible = "fsl,imx8ulp-wdt", },
-	{ .compatible = "fsl,imx7ulp-wdt", },
+	{ .compatible = "fsl,imx8ulp-wdt", .data = &imx7ulp_wdt_hw, },
+	{ .compatible = "fsl,imx7ulp-wdt", .data = &imx7ulp_wdt_hw, },
+	{ .compatible = "fsl,imx93-wdt", .data = &imx93_wdt_hw, },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, imx7ulp_wdt_dt_ids);
-- 
2.17.1


      parent reply	other threads:[~2022-08-16  7:09 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-16  4:36 [PATCH 0/7] watchdog: imx7ulp_wdt: update i.MX7ULP WDOG timer driver Alice Guo (OSS)
2022-08-16  4:36 ` [PATCH 1/7] watchdog: imx7ulp: Move suspend/resume to noirq phase Alice Guo (OSS)
2022-08-16  4:36 ` [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence Alice Guo (OSS)
2022-08-16  6:23   ` Marco Felsch
2022-08-22  7:49     ` Alice Guo (OSS)
2022-08-22  8:00       ` Marco Felsch
2022-08-22 14:03         ` Guenter Roeck
2022-08-23  5:38           ` Alice Guo (OSS)
2022-08-23  9:10             ` Marco Felsch
2022-08-23 12:02               ` Guenter Roeck
2022-08-24  6:24                 ` Alice Guo (OSS)
2022-08-24  8:03                   ` Marco Felsch
2022-08-24  8:40                     ` Alice Guo (OSS)
2022-08-24  9:06                       ` Marco Felsch
2022-08-24 10:05                         ` Alice Guo (OSS)
2022-08-25  7:50                           ` Marco Felsch
2022-08-25  8:08                             ` Alice Guo (OSS)
2022-08-25  9:01                               ` Marco Felsch
2022-08-25 10:11                                 ` Alice Guo (OSS)
2022-08-16  4:36 ` [PATCH 3/7] watchdog: imx7ulp_wdt: Check CMD32EN in wdog init Alice Guo (OSS)
2022-08-22 14:05   ` Guenter Roeck
2022-08-23  5:46     ` Alice Guo (OSS)
2022-08-23 12:05       ` Guenter Roeck
2022-08-16  4:36 ` [PATCH 4/7] watchdog: imx7ulp_wdt: Fix RCS timeout issue Alice Guo (OSS)
2022-08-22 14:09   ` Guenter Roeck
2022-08-23  5:59     ` Alice Guo (OSS)
2022-08-23 12:06       ` Guenter Roeck
2022-08-24  6:44         ` Alice Guo (OSS)
2022-08-16  4:36 ` [PATCH 5/7] watchdog: imx7ulp_wdt: Handle wdog reconfigure failure Alice Guo (OSS)
2022-08-16  4:36 ` [PATCH 6/7] watchdog: imx7ulp_wdt: init wdog when it was active Alice Guo (OSS)
2022-08-16  4:36 ` Alice Guo (OSS) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220816043643.26569-8-alice.guo@oss.nxp.com \
    --to=alice.guo@oss.nxp.com \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=wim@linux-watchdog.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).