Lines Matching +full:wdt +full:- +full:enable +full:- +full:once
1 // SPDX-License-Identifier: GPL-2.0
53 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
77 return -ETIMEDOUT; in imx7ulp_wdt_wait_ulk()
82 static int imx7ulp_wdt_wait_rcs(struct imx7ulp_wdt_device *wdt) in imx7ulp_wdt_wait_rcs() argument
85 u32 val = readl(wdt->base + WDOG_CS); in imx7ulp_wdt_wait_rcs()
92 readl_poll_timeout(wdt->base + WDOG_CS, val, val & WDOG_CS_RCS, 100, in imx7ulp_wdt_wait_rcs()
94 ret = -ETIMEDOUT; in imx7ulp_wdt_wait_rcs()
97 if (wdt->post_rcs_wait) in imx7ulp_wdt_wait_rcs()
103 static int _imx7ulp_wdt_enable(struct imx7ulp_wdt_device *wdt, bool enable) in _imx7ulp_wdt_enable() argument
105 u32 val = readl(wdt->base + WDOG_CS); in _imx7ulp_wdt_enable()
109 writel(UNLOCK, wdt->base + WDOG_CNT); in _imx7ulp_wdt_enable()
110 ret = imx7ulp_wdt_wait_ulk(wdt->base); in _imx7ulp_wdt_enable()
113 if (enable) in _imx7ulp_wdt_enable()
114 writel(val | WDOG_CS_EN, wdt->base + WDOG_CS); in _imx7ulp_wdt_enable()
116 writel(val & ~WDOG_CS_EN, wdt->base + WDOG_CS); in _imx7ulp_wdt_enable()
119 ret = imx7ulp_wdt_wait_rcs(wdt); in _imx7ulp_wdt_enable()
128 static int imx7ulp_wdt_enable(struct watchdog_device *wdog, bool enable) in imx7ulp_wdt_enable() argument
130 struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog); in imx7ulp_wdt_enable() local
136 ret = _imx7ulp_wdt_enable(wdt, enable); in imx7ulp_wdt_enable()
137 val = readl(wdt->base + WDOG_CS); in imx7ulp_wdt_enable()
138 } while (--loop > 0 && ((!!(val & WDOG_CS_EN)) != enable || ret)); in imx7ulp_wdt_enable()
141 return -EBUSY; in imx7ulp_wdt_enable()
148 struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog); in imx7ulp_wdt_ping() local
150 writel(REFRESH, wdt->base + WDOG_CNT); in imx7ulp_wdt_ping()
165 static int _imx7ulp_wdt_set_timeout(struct imx7ulp_wdt_device *wdt, in _imx7ulp_wdt_set_timeout() argument
171 writel(UNLOCK, wdt->base + WDOG_CNT); in _imx7ulp_wdt_set_timeout()
172 ret = imx7ulp_wdt_wait_ulk(wdt->base); in _imx7ulp_wdt_set_timeout()
175 writel(toval, wdt->base + WDOG_TOVAL); in _imx7ulp_wdt_set_timeout()
177 ret = imx7ulp_wdt_wait_rcs(wdt); in _imx7ulp_wdt_set_timeout()
188 struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog); in imx7ulp_wdt_set_timeout() local
189 u32 toval = wdt->hw->wdog_clock_rate * timeout; in imx7ulp_wdt_set_timeout()
195 ret = _imx7ulp_wdt_set_timeout(wdt, toval); in imx7ulp_wdt_set_timeout()
196 val = readl(wdt->base + WDOG_TOVAL); in imx7ulp_wdt_set_timeout()
197 } while (--loop > 0 && (val != toval || ret)); in imx7ulp_wdt_set_timeout()
200 return -EBUSY; in imx7ulp_wdt_set_timeout()
202 wdog->timeout = timeout; in imx7ulp_wdt_set_timeout()
209 struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog); in imx7ulp_wdt_restart() local
216 ret = imx7ulp_wdt_set_timeout(&wdt->wdd, 1); in imx7ulp_wdt_restart()
242 static int _imx7ulp_wdt_init(struct imx7ulp_wdt_device *wdt, unsigned int timeout, unsigned int cs) in _imx7ulp_wdt_init() argument
249 val = readl(wdt->base + WDOG_CS); in _imx7ulp_wdt_init()
251 writel(UNLOCK, wdt->base + WDOG_CNT); in _imx7ulp_wdt_init()
255 writel_relaxed(UNLOCK_SEQ0, wdt->base + WDOG_CNT); in _imx7ulp_wdt_init()
256 writel_relaxed(UNLOCK_SEQ1, wdt->base + WDOG_CNT); in _imx7ulp_wdt_init()
260 ret = imx7ulp_wdt_wait_ulk(wdt->base); in _imx7ulp_wdt_init()
265 writel(timeout, wdt->base + WDOG_TOVAL); in _imx7ulp_wdt_init()
266 writel(cs, wdt->base + WDOG_CS); in _imx7ulp_wdt_init()
268 ret = imx7ulp_wdt_wait_rcs(wdt); in _imx7ulp_wdt_init()
277 static int imx7ulp_wdt_init(struct imx7ulp_wdt_device *wdt, unsigned int timeout) in imx7ulp_wdt_init() argument
279 /* enable 32bit command sequence and reconfigure */ in imx7ulp_wdt_init()
286 if (wdt->hw->prescaler_enable) in imx7ulp_wdt_init()
290 ret = _imx7ulp_wdt_init(wdt, timeout, val); in imx7ulp_wdt_init()
291 toval = readl(wdt->base + WDOG_TOVAL); in imx7ulp_wdt_init()
292 cs = readl(wdt->base + WDOG_CS); in imx7ulp_wdt_init()
294 } while (--loop > 0 && (cs != val || toval != timeout || ret)); in imx7ulp_wdt_init()
297 return -EBUSY; in imx7ulp_wdt_init()
310 struct device *dev = &pdev->dev; in imx7ulp_wdt_probe()
316 return -ENOMEM; in imx7ulp_wdt_probe()
320 imx7ulp_wdt->base = devm_platform_ioremap_resource(pdev, 0); in imx7ulp_wdt_probe()
321 if (IS_ERR(imx7ulp_wdt->base)) in imx7ulp_wdt_probe()
322 return PTR_ERR(imx7ulp_wdt->base); in imx7ulp_wdt_probe()
324 imx7ulp_wdt->clk = devm_clk_get(dev, NULL); in imx7ulp_wdt_probe()
325 if (IS_ERR(imx7ulp_wdt->clk)) { in imx7ulp_wdt_probe()
327 return PTR_ERR(imx7ulp_wdt->clk); in imx7ulp_wdt_probe()
330 imx7ulp_wdt->post_rcs_wait = true; in imx7ulp_wdt_probe()
331 if (of_device_is_compatible(dev->of_node, in imx7ulp_wdt_probe()
332 "fsl,imx8ulp-wdt")) { in imx7ulp_wdt_probe()
333 dev_info(dev, "imx8ulp wdt probe\n"); in imx7ulp_wdt_probe()
334 imx7ulp_wdt->post_rcs_wait = false; in imx7ulp_wdt_probe()
336 dev_info(dev, "imx7ulp wdt probe\n"); in imx7ulp_wdt_probe()
339 ret = clk_prepare_enable(imx7ulp_wdt->clk); in imx7ulp_wdt_probe()
343 ret = devm_add_action_or_reset(dev, imx7ulp_wdt_action, imx7ulp_wdt->clk); in imx7ulp_wdt_probe()
347 wdog = &imx7ulp_wdt->wdd; in imx7ulp_wdt_probe()
348 wdog->info = &imx7ulp_wdt_info; in imx7ulp_wdt_probe()
349 wdog->ops = &imx7ulp_wdt_ops; in imx7ulp_wdt_probe()
350 wdog->min_timeout = 1; in imx7ulp_wdt_probe()
351 wdog->max_timeout = MAX_TIMEOUT; in imx7ulp_wdt_probe()
352 wdog->parent = dev; in imx7ulp_wdt_probe()
353 wdog->timeout = DEFAULT_TIMEOUT; in imx7ulp_wdt_probe()
360 imx7ulp_wdt->hw = of_device_get_match_data(dev); in imx7ulp_wdt_probe()
361 ret = imx7ulp_wdt_init(imx7ulp_wdt, wdog->timeout * imx7ulp_wdt->hw->wdog_clock_rate); in imx7ulp_wdt_probe()
372 if (watchdog_active(&imx7ulp_wdt->wdd)) in imx7ulp_wdt_suspend_noirq()
373 imx7ulp_wdt_stop(&imx7ulp_wdt->wdd); in imx7ulp_wdt_suspend_noirq()
375 clk_disable_unprepare(imx7ulp_wdt->clk); in imx7ulp_wdt_suspend_noirq()
383 u32 timeout = imx7ulp_wdt->wdd.timeout * imx7ulp_wdt->hw->wdog_clock_rate; in imx7ulp_wdt_resume_noirq()
386 ret = clk_prepare_enable(imx7ulp_wdt->clk); in imx7ulp_wdt_resume_noirq()
390 if (watchdog_active(&imx7ulp_wdt->wdd)) { in imx7ulp_wdt_resume_noirq()
392 imx7ulp_wdt_start(&imx7ulp_wdt->wdd); in imx7ulp_wdt_resume_noirq()
393 imx7ulp_wdt_ping(&imx7ulp_wdt->wdd); in imx7ulp_wdt_resume_noirq()
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, },
425 .name = "imx7ulp-wdt",