Skip to content

Commit 8ed2dc4

Browse files
Alice GuoWim Van Sebroeck
authored andcommitted
watchdog: imx93: add watchdog timer on imx93
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 <[email protected]> Signed-off-by: Alice Guo <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Wim Van Sebroeck <[email protected]>
1 parent cef6bc9 commit 8ed2dc4

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

drivers/watchdog/imx7ulp_wdt.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/kernel.h>
1010
#include <linux/module.h>
1111
#include <linux/of.h>
12+
#include <linux/of_device.h>
1213
#include <linux/platform_device.h>
1314
#include <linux/reboot.h>
1415
#include <linux/watchdog.h>
@@ -52,11 +53,17 @@ module_param(nowayout, bool, 0000);
5253
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
5354
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
5455

56+
struct imx_wdt_hw_feature {
57+
bool prescaler_enable;
58+
u32 wdog_clock_rate;
59+
};
60+
5561
struct imx7ulp_wdt_device {
5662
struct watchdog_device wdd;
5763
void __iomem *base;
5864
struct clk *clk;
5965
bool post_rcs_wait;
66+
const struct imx_wdt_hw_feature *hw;
6067
};
6168

6269
static int imx7ulp_wdt_wait_ulk(void __iomem *base)
@@ -179,7 +186,7 @@ static int imx7ulp_wdt_set_timeout(struct watchdog_device *wdog,
179186
unsigned int timeout)
180187
{
181188
struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog);
182-
u32 toval = WDOG_CLOCK_RATE * timeout;
189+
u32 toval = wdt->hw->wdog_clock_rate * timeout;
183190
u32 val;
184191
int ret;
185192
u32 loop = RETRY_MAX;
@@ -276,6 +283,9 @@ static int imx7ulp_wdt_init(struct imx7ulp_wdt_device *wdt, unsigned int timeout
276283
int ret;
277284
u32 loop = RETRY_MAX;
278285

286+
if (wdt->hw->prescaler_enable)
287+
val |= WDOG_CS_PRES;
288+
279289
do {
280290
ret = _imx7ulp_wdt_init(wdt, timeout, val);
281291
toval = readl(wdt->base + WDOG_TOVAL);
@@ -346,7 +356,9 @@ static int imx7ulp_wdt_probe(struct platform_device *pdev)
346356
watchdog_stop_on_reboot(wdog);
347357
watchdog_stop_on_unregister(wdog);
348358
watchdog_set_drvdata(wdog, imx7ulp_wdt);
349-
ret = imx7ulp_wdt_init(imx7ulp_wdt, wdog->timeout * WDOG_CLOCK_RATE);
359+
360+
imx7ulp_wdt->hw = of_device_get_match_data(dev);
361+
ret = imx7ulp_wdt_init(imx7ulp_wdt, wdog->timeout * imx7ulp_wdt->hw->wdog_clock_rate);
350362
if (ret)
351363
return ret;
352364

@@ -368,7 +380,7 @@ static int __maybe_unused imx7ulp_wdt_suspend_noirq(struct device *dev)
368380
static int __maybe_unused imx7ulp_wdt_resume_noirq(struct device *dev)
369381
{
370382
struct imx7ulp_wdt_device *imx7ulp_wdt = dev_get_drvdata(dev);
371-
u32 timeout = imx7ulp_wdt->wdd.timeout * WDOG_CLOCK_RATE;
383+
u32 timeout = imx7ulp_wdt->wdd.timeout * imx7ulp_wdt->hw->wdog_clock_rate;
372384
int ret;
373385

374386
ret = clk_prepare_enable(imx7ulp_wdt->clk);
@@ -389,9 +401,20 @@ static const struct dev_pm_ops imx7ulp_wdt_pm_ops = {
389401
imx7ulp_wdt_resume_noirq)
390402
};
391403

404+
static const struct imx_wdt_hw_feature imx7ulp_wdt_hw = {
405+
.prescaler_enable = false,
406+
.wdog_clock_rate = 1000,
407+
};
408+
409+
static const struct imx_wdt_hw_feature imx93_wdt_hw = {
410+
.prescaler_enable = true,
411+
.wdog_clock_rate = 125,
412+
};
413+
392414
static const struct of_device_id imx7ulp_wdt_dt_ids[] = {
393-
{ .compatible = "fsl,imx8ulp-wdt", },
394-
{ .compatible = "fsl,imx7ulp-wdt", },
415+
{ .compatible = "fsl,imx8ulp-wdt", .data = &imx7ulp_wdt_hw, },
416+
{ .compatible = "fsl,imx7ulp-wdt", .data = &imx7ulp_wdt_hw, },
417+
{ .compatible = "fsl,imx93-wdt", .data = &imx93_wdt_hw, },
395418
{ /* sentinel */ }
396419
};
397420
MODULE_DEVICE_TABLE(of, imx7ulp_wdt_dt_ids);

0 commit comments

Comments
 (0)