mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] watchdog: imxulp: Fix timeout calculation
@ 2024-01-15 15:56 Sascha Hauer
  2024-01-15 15:56 ` [PATCH 2/2] watchdog: imxulp: Fix prescaler setting on i.MX7ulp Sascha Hauer
  2024-01-16  6:53 ` [PATCH 1/2] watchdog: imxulp: Fix timeout calculation Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-01-15 15:56 UTC (permalink / raw)
  To: Barebox List

On i.MX93 the 32k clock runs at 32768Hz. Together with the /256
prescaler the watchdog timer advances 32768/256 = 128 ticks per
second, not 125.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/watchdog/imxulp-wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/watchdog/imxulp-wdt.c b/drivers/watchdog/imxulp-wdt.c
index 78d1527782..84d558b812 100644
--- a/drivers/watchdog/imxulp-wdt.c
+++ b/drivers/watchdog/imxulp-wdt.c
@@ -50,7 +50,7 @@ struct imxulp_wd {
 #define WDOG_TOVAL		0x8
 
 #define CLK_RATE_1KHZ		1000
-#define CLK_RATE_32KHZ		125
+#define CLK_RATE_32KHZ		128
 
 static int imxulp_watchdog_set_timeout(struct watchdog *wd, unsigned int timeout)
 {
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] watchdog: imxulp: Fix prescaler setting on i.MX7ulp
  2024-01-15 15:56 [PATCH 1/2] watchdog: imxulp: Fix timeout calculation Sascha Hauer
@ 2024-01-15 15:56 ` Sascha Hauer
  2024-01-16  6:53 ` [PATCH 1/2] watchdog: imxulp: Fix timeout calculation Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-01-15 15:56 UTC (permalink / raw)
  To: Barebox List

On i.MX7ulp the driver assumes a clock tick rate of 1kHz. This is only
true though when the /256 prescaler is disabled. To fix this we disable
the prescaler on i.MX7ulp while keeping it enabled on i.MX93. We derived
this bug from U-Boot, the Kernel does this correctly and has the same
code as we introduce here now.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/watchdog/imxulp-wdt.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/watchdog/imxulp-wdt.c b/drivers/watchdog/imxulp-wdt.c
index 84d558b812..5a89876175 100644
--- a/drivers/watchdog/imxulp-wdt.c
+++ b/drivers/watchdog/imxulp-wdt.c
@@ -16,14 +16,16 @@
 #include <asm/system.h>
 
 struct imxulp_socdata {
+	bool prescaler_enable;
 	unsigned int rate;
 };
 
 struct imxulp_wd {
 	struct watchdog wd;
 	void __iomem *base;
-	unsigned int rate;
+	bool prescaler_enable;
 	struct device *dev;
+	const struct imxulp_socdata *socdata;
 };
 
 #define REFRESH_WORD0 0xA602 /* 1st refresh word */
@@ -72,10 +74,13 @@ static int imxulp_watchdog_set_timeout(struct watchdog *wd, unsigned int timeout
 	while (!(readl(imxwd->base + WDOG_CS) & WDOG_CS_ULK))
 		;
 
-	writel(timeout * imxwd->rate, imxwd->base + WDOG_TOVAL);
+	writel(timeout * imxwd->socdata->rate, imxwd->base + WDOG_TOVAL);
+
+	if (imxwd->socdata->prescaler_enable)
+		cmd32 |= WDOG_CS_PRES;
 
 	writel(cmd32 | WDOG_CS_EN | WDOG_CS_UPDATE | WDOG_CS_LPO_CLK |
-	       WDOG_CS_FLG | WDOG_CS_PRES | WDOG_CS_INT, imxwd->base + WDOG_CS);
+	       WDOG_CS_FLG | WDOG_CS_INT, imxwd->base + WDOG_CS);
 
 	/* Wait WDOG reconfiguration */
 	while (!(readl(imxwd->base + WDOG_CS) & WDOG_CS_RCS))
@@ -115,10 +120,10 @@ static int imxulp_wd_probe(struct device *dev)
 	if (IS_ERR(iores))
 		return dev_err_probe(dev, PTR_ERR(iores), "could not get memory region\n");
 
-	imxwd->rate = socdata->rate;
+	imxwd->socdata = socdata;
 	imxwd->base = IOMEM(iores->start);
 	imxwd->wd.set_timeout = imxulp_watchdog_set_timeout;
-	imxwd->wd.timeout_max = 0xffff / imxwd->rate;
+	imxwd->wd.timeout_max = 0xffff / imxwd->socdata->rate;
 	imxwd->wd.hwdev = dev;
 	imxwd->wd.running = imxulp_wd_running(imxwd);
 
@@ -130,10 +135,12 @@ static int imxulp_wd_probe(struct device *dev)
 }
 
 static struct imxulp_socdata imx7ulp_wd_socdata = {
+	.prescaler_enable = false,
 	.rate = CLK_RATE_1KHZ,
 };
 
 static struct imxulp_socdata imx93_wd_socdata = {
+	.prescaler_enable = true,
 	.rate = CLK_RATE_32KHZ,
 };
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] watchdog: imxulp: Fix timeout calculation
  2024-01-15 15:56 [PATCH 1/2] watchdog: imxulp: Fix timeout calculation Sascha Hauer
  2024-01-15 15:56 ` [PATCH 2/2] watchdog: imxulp: Fix prescaler setting on i.MX7ulp Sascha Hauer
@ 2024-01-16  6:53 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-01-16  6:53 UTC (permalink / raw)
  To: Barebox List, Sascha Hauer


On Mon, 15 Jan 2024 16:56:14 +0100, Sascha Hauer wrote:
> On i.MX93 the 32k clock runs at 32768Hz. Together with the /256
> prescaler the watchdog timer advances 32768/256 = 128 ticks per
> second, not 125.
> 
> 

Applied, thanks!

[1/2] watchdog: imxulp: Fix timeout calculation
      https://git.pengutronix.de/cgit/barebox/commit/?id=96b145148467 (link may not be stable)
[2/2] watchdog: imxulp: Fix prescaler setting on i.MX7ulp
      https://git.pengutronix.de/cgit/barebox/commit/?id=519d1c00f3e5 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-16  6:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-15 15:56 [PATCH 1/2] watchdog: imxulp: Fix timeout calculation Sascha Hauer
2024-01-15 15:56 ` [PATCH 2/2] watchdog: imxulp: Fix prescaler setting on i.MX7ulp Sascha Hauer
2024-01-16  6:53 ` [PATCH 1/2] watchdog: imxulp: Fix timeout calculation Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox