Lines Matching +full:imx7ulp +full:- +full:wdt
1 // SPDX-License-Identifier: GPL-2.0
76 return -ETIMEDOUT; in imx7ulp_wdt_wait_ulk()
81 static int imx7ulp_wdt_wait_rcs(struct imx7ulp_wdt_device *wdt) in imx7ulp_wdt_wait_rcs() argument
84 u32 val = readl(wdt->base + WDOG_CS); in imx7ulp_wdt_wait_rcs()
91 readl_poll_timeout(wdt->base + WDOG_CS, val, val & WDOG_CS_RCS, 100, in imx7ulp_wdt_wait_rcs()
93 ret = -ETIMEDOUT; in imx7ulp_wdt_wait_rcs()
96 if (wdt->post_rcs_wait) in imx7ulp_wdt_wait_rcs()
102 static int _imx7ulp_wdt_enable(struct imx7ulp_wdt_device *wdt, bool enable) in _imx7ulp_wdt_enable() argument
104 u32 val = readl(wdt->base + WDOG_CS); in _imx7ulp_wdt_enable()
108 writel(UNLOCK, wdt->base + WDOG_CNT); in _imx7ulp_wdt_enable()
109 ret = imx7ulp_wdt_wait_ulk(wdt->base); in _imx7ulp_wdt_enable()
113 writel(val | WDOG_CS_EN, wdt->base + WDOG_CS); in _imx7ulp_wdt_enable()
115 writel(val & ~WDOG_CS_EN, wdt->base + WDOG_CS); in _imx7ulp_wdt_enable()
118 ret = imx7ulp_wdt_wait_rcs(wdt); in _imx7ulp_wdt_enable()
129 struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog); in imx7ulp_wdt_enable() local
135 ret = _imx7ulp_wdt_enable(wdt, enable); in imx7ulp_wdt_enable()
136 val = readl(wdt->base + WDOG_CS); in imx7ulp_wdt_enable()
137 } while (--loop > 0 && ((!!(val & WDOG_CS_EN)) != enable || ret)); in imx7ulp_wdt_enable()
140 return -EBUSY; in imx7ulp_wdt_enable()
147 struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog); in imx7ulp_wdt_ping() local
149 writel(REFRESH, wdt->base + WDOG_CNT); in imx7ulp_wdt_ping()
164 static int _imx7ulp_wdt_set_timeout(struct imx7ulp_wdt_device *wdt, in _imx7ulp_wdt_set_timeout() argument
170 writel(UNLOCK, wdt->base + WDOG_CNT); in _imx7ulp_wdt_set_timeout()
171 ret = imx7ulp_wdt_wait_ulk(wdt->base); in _imx7ulp_wdt_set_timeout()
174 writel(toval, wdt->base + WDOG_TOVAL); in _imx7ulp_wdt_set_timeout()
176 ret = imx7ulp_wdt_wait_rcs(wdt); in _imx7ulp_wdt_set_timeout()
187 struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog); in imx7ulp_wdt_set_timeout() local
188 u32 toval = wdt->hw->wdog_clock_rate * timeout; in imx7ulp_wdt_set_timeout()
194 ret = _imx7ulp_wdt_set_timeout(wdt, toval); in imx7ulp_wdt_set_timeout()
195 val = readl(wdt->base + WDOG_TOVAL); in imx7ulp_wdt_set_timeout()
196 } while (--loop > 0 && (val != toval || ret)); in imx7ulp_wdt_set_timeout()
199 return -EBUSY; in imx7ulp_wdt_set_timeout()
201 wdog->timeout = timeout; in imx7ulp_wdt_set_timeout()
208 struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog); in imx7ulp_wdt_restart() local
215 ret = imx7ulp_wdt_set_timeout(&wdt->wdd, 1); in imx7ulp_wdt_restart()
241 static int _imx7ulp_wdt_init(struct imx7ulp_wdt_device *wdt, unsigned int timeout, unsigned int cs) in _imx7ulp_wdt_init() argument
248 val = readl(wdt->base + WDOG_CS); in _imx7ulp_wdt_init()
250 writel(UNLOCK, wdt->base + WDOG_CNT); in _imx7ulp_wdt_init()
254 writel_relaxed(UNLOCK_SEQ0, wdt->base + WDOG_CNT); in _imx7ulp_wdt_init()
255 writel_relaxed(UNLOCK_SEQ1, wdt->base + WDOG_CNT); in _imx7ulp_wdt_init()
259 ret = imx7ulp_wdt_wait_ulk(wdt->base); in _imx7ulp_wdt_init()
264 writel(timeout, wdt->base + WDOG_TOVAL); in _imx7ulp_wdt_init()
265 writel(cs, wdt->base + WDOG_CS); in _imx7ulp_wdt_init()
267 ret = imx7ulp_wdt_wait_rcs(wdt); in _imx7ulp_wdt_init()
276 static int imx7ulp_wdt_init(struct imx7ulp_wdt_device *wdt, unsigned int timeout) in imx7ulp_wdt_init() argument
285 if (wdt->hw->prescaler_enable) in imx7ulp_wdt_init()
289 ret = _imx7ulp_wdt_init(wdt, timeout, val); in imx7ulp_wdt_init()
290 toval = readl(wdt->base + WDOG_TOVAL); in imx7ulp_wdt_init()
291 cs = readl(wdt->base + WDOG_CS); in imx7ulp_wdt_init()
293 } while (--loop > 0 && (cs != val || toval != timeout || ret)); in imx7ulp_wdt_init()
296 return -EBUSY; in imx7ulp_wdt_init()
304 struct device *dev = &pdev->dev; in imx7ulp_wdt_probe()
310 return -ENOMEM; in imx7ulp_wdt_probe()
314 imx7ulp_wdt->base = devm_platform_ioremap_resource(pdev, 0); in imx7ulp_wdt_probe()
315 if (IS_ERR(imx7ulp_wdt->base)) in imx7ulp_wdt_probe()
316 return PTR_ERR(imx7ulp_wdt->base); in imx7ulp_wdt_probe()
318 imx7ulp_wdt->clk = devm_clk_get_enabled(dev, NULL); in imx7ulp_wdt_probe()
319 if (IS_ERR(imx7ulp_wdt->clk)) { in imx7ulp_wdt_probe()
321 return PTR_ERR(imx7ulp_wdt->clk); in imx7ulp_wdt_probe()
324 imx7ulp_wdt->post_rcs_wait = true; in imx7ulp_wdt_probe()
325 if (of_device_is_compatible(dev->of_node, in imx7ulp_wdt_probe()
326 "fsl,imx8ulp-wdt")) { in imx7ulp_wdt_probe()
327 dev_info(dev, "imx8ulp wdt probe\n"); in imx7ulp_wdt_probe()
328 imx7ulp_wdt->post_rcs_wait = false; in imx7ulp_wdt_probe()
330 dev_info(dev, "imx7ulp wdt probe\n"); in imx7ulp_wdt_probe()
333 wdog = &imx7ulp_wdt->wdd; in imx7ulp_wdt_probe()
334 wdog->info = &imx7ulp_wdt_info; in imx7ulp_wdt_probe()
335 wdog->ops = &imx7ulp_wdt_ops; in imx7ulp_wdt_probe()
336 wdog->min_timeout = 1; in imx7ulp_wdt_probe()
337 wdog->max_timeout = MAX_TIMEOUT; in imx7ulp_wdt_probe()
338 wdog->parent = dev; in imx7ulp_wdt_probe()
339 wdog->timeout = DEFAULT_TIMEOUT; in imx7ulp_wdt_probe()
346 imx7ulp_wdt->hw = of_device_get_match_data(dev); in imx7ulp_wdt_probe()
347 ret = imx7ulp_wdt_init(imx7ulp_wdt, wdog->timeout * imx7ulp_wdt->hw->wdog_clock_rate); in imx7ulp_wdt_probe()
358 if (watchdog_active(&imx7ulp_wdt->wdd)) in imx7ulp_wdt_suspend_noirq()
359 imx7ulp_wdt_stop(&imx7ulp_wdt->wdd); in imx7ulp_wdt_suspend_noirq()
361 clk_disable_unprepare(imx7ulp_wdt->clk); in imx7ulp_wdt_suspend_noirq()
369 u32 timeout = imx7ulp_wdt->wdd.timeout * imx7ulp_wdt->hw->wdog_clock_rate; in imx7ulp_wdt_resume_noirq()
372 ret = clk_prepare_enable(imx7ulp_wdt->clk); in imx7ulp_wdt_resume_noirq()
376 if (watchdog_active(&imx7ulp_wdt->wdd)) { in imx7ulp_wdt_resume_noirq()
378 imx7ulp_wdt_start(&imx7ulp_wdt->wdd); in imx7ulp_wdt_resume_noirq()
379 imx7ulp_wdt_ping(&imx7ulp_wdt->wdd); in imx7ulp_wdt_resume_noirq()
401 { .compatible = "fsl,imx8ulp-wdt", .data = &imx7ulp_wdt_hw, },
402 { .compatible = "fsl,imx7ulp-wdt", .data = &imx7ulp_wdt_hw, },
403 { .compatible = "fsl,imx93-wdt", .data = &imx93_wdt_hw, },
411 .name = "imx7ulp-wdt",