Lines Matching +full:timer +full:- +full:watchdog
1 // SPDX-License-Identifier: GPL-2.0-only
3 * NXP LPC18xx Watchdog Timer (WDT)
8 * -----
9 * The Watchdog consists of a fixed divide-by-4 clock pre-scaler and a 24-bit
18 #include <linux/watchdog.h>
35 /* Clock pre-scaler */
43 MODULE_PARM_DESC(heartbeat, "Watchdog heartbeats in seconds (default="
48 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
57 struct timer_list timer; member
70 spin_lock_irqsave(&lpc18xx_wdt->lock, flags); in lpc18xx_wdt_feed()
71 writel(LPC18XX_WDT_FEED_MAGIC1, lpc18xx_wdt->base + LPC18XX_WDT_FEED); in lpc18xx_wdt_feed()
72 writel(LPC18XX_WDT_FEED_MAGIC2, lpc18xx_wdt->base + LPC18XX_WDT_FEED); in lpc18xx_wdt_feed()
73 spin_unlock_irqrestore(&lpc18xx_wdt->lock, flags); in lpc18xx_wdt_feed()
80 struct lpc18xx_wdt_dev *lpc18xx_wdt = from_timer(lpc18xx_wdt, t, timer); in lpc18xx_wdt_timer_feed()
81 struct watchdog_device *wdt_dev = &lpc18xx_wdt->wdt_dev; in lpc18xx_wdt_timer_feed()
86 mod_timer(&lpc18xx_wdt->timer, jiffies + in lpc18xx_wdt_timer_feed()
87 msecs_to_jiffies((wdt_dev->timeout * MSEC_PER_SEC) / 2)); in lpc18xx_wdt_timer_feed()
91 * Since LPC18xx Watchdog cannot be disabled in hardware, we must keep feeding
92 * it with a timer until userspace watchdog software takes over.
98 lpc18xx_wdt_timer_feed(&lpc18xx_wdt->timer); in lpc18xx_wdt_stop()
107 val = DIV_ROUND_UP(lpc18xx_wdt->wdt_dev.timeout * lpc18xx_wdt->clk_rate, in __lpc18xx_wdt_set_timeout()
109 writel(val, lpc18xx_wdt->base + LPC18XX_WDT_TC); in __lpc18xx_wdt_set_timeout()
117 lpc18xx_wdt->wdt_dev.timeout = new_timeout; in lpc18xx_wdt_set_timeout()
128 val = readl(lpc18xx_wdt->base + LPC18XX_WDT_TV); in lpc18xx_wdt_get_timeleft()
129 return (val * LPC18XX_WDT_CLK_DIV) / lpc18xx_wdt->clk_rate; in lpc18xx_wdt_get_timeleft()
137 if (timer_pending(&lpc18xx_wdt->timer)) in lpc18xx_wdt_start()
138 del_timer(&lpc18xx_wdt->timer); in lpc18xx_wdt_start()
140 val = readl(lpc18xx_wdt->base + LPC18XX_WDT_MOD); in lpc18xx_wdt_start()
143 writel(val, lpc18xx_wdt->base + LPC18XX_WDT_MOD); in lpc18xx_wdt_start()
147 * enable the Watchdog. A valid feed sequence must be completed after in lpc18xx_wdt_start()
148 * setting WDEN before the Watchdog is capable of generating a reset. in lpc18xx_wdt_start()
163 * Incorrect feed sequence causes immediate watchdog reset if enabled. in lpc18xx_wdt_restart()
165 spin_lock_irqsave(&lpc18xx_wdt->lock, flags); in lpc18xx_wdt_restart()
167 val = readl(lpc18xx_wdt->base + LPC18XX_WDT_MOD); in lpc18xx_wdt_restart()
170 writel(val, lpc18xx_wdt->base + LPC18XX_WDT_MOD); in lpc18xx_wdt_restart()
172 writel(LPC18XX_WDT_FEED_MAGIC1, lpc18xx_wdt->base + LPC18XX_WDT_FEED); in lpc18xx_wdt_restart()
173 writel(LPC18XX_WDT_FEED_MAGIC2, lpc18xx_wdt->base + LPC18XX_WDT_FEED); in lpc18xx_wdt_restart()
175 writel(LPC18XX_WDT_FEED_MAGIC1, lpc18xx_wdt->base + LPC18XX_WDT_FEED); in lpc18xx_wdt_restart()
176 writel(LPC18XX_WDT_FEED_MAGIC1, lpc18xx_wdt->base + LPC18XX_WDT_FEED); in lpc18xx_wdt_restart()
178 spin_unlock_irqrestore(&lpc18xx_wdt->lock, flags); in lpc18xx_wdt_restart()
184 .identity = "NXP LPC18xx Watchdog",
208 struct device *dev = &pdev->dev; in lpc18xx_wdt_probe()
213 return -ENOMEM; in lpc18xx_wdt_probe()
215 lpc18xx_wdt->base = devm_platform_ioremap_resource(pdev, 0); in lpc18xx_wdt_probe()
216 if (IS_ERR(lpc18xx_wdt->base)) in lpc18xx_wdt_probe()
217 return PTR_ERR(lpc18xx_wdt->base); in lpc18xx_wdt_probe()
219 lpc18xx_wdt->reg_clk = devm_clk_get(dev, "reg"); in lpc18xx_wdt_probe()
220 if (IS_ERR(lpc18xx_wdt->reg_clk)) { in lpc18xx_wdt_probe()
222 return PTR_ERR(lpc18xx_wdt->reg_clk); in lpc18xx_wdt_probe()
225 lpc18xx_wdt->wdt_clk = devm_clk_get(dev, "wdtclk"); in lpc18xx_wdt_probe()
226 if (IS_ERR(lpc18xx_wdt->wdt_clk)) { in lpc18xx_wdt_probe()
228 return PTR_ERR(lpc18xx_wdt->wdt_clk); in lpc18xx_wdt_probe()
231 ret = clk_prepare_enable(lpc18xx_wdt->reg_clk); in lpc18xx_wdt_probe()
237 lpc18xx_wdt->reg_clk); in lpc18xx_wdt_probe()
241 ret = clk_prepare_enable(lpc18xx_wdt->wdt_clk); in lpc18xx_wdt_probe()
247 lpc18xx_wdt->wdt_clk); in lpc18xx_wdt_probe()
252 lpc18xx_wdt->clk_rate = clk_get_rate(lpc18xx_wdt->wdt_clk); in lpc18xx_wdt_probe()
253 if (lpc18xx_wdt->clk_rate == 0) { in lpc18xx_wdt_probe()
255 return -EINVAL; in lpc18xx_wdt_probe()
258 lpc18xx_wdt->wdt_dev.info = &lpc18xx_wdt_info; in lpc18xx_wdt_probe()
259 lpc18xx_wdt->wdt_dev.ops = &lpc18xx_wdt_ops; in lpc18xx_wdt_probe()
261 lpc18xx_wdt->wdt_dev.min_timeout = DIV_ROUND_UP(LPC18XX_WDT_TC_MIN * in lpc18xx_wdt_probe()
262 LPC18XX_WDT_CLK_DIV, lpc18xx_wdt->clk_rate); in lpc18xx_wdt_probe()
264 lpc18xx_wdt->wdt_dev.max_timeout = (LPC18XX_WDT_TC_MAX * in lpc18xx_wdt_probe()
265 LPC18XX_WDT_CLK_DIV) / lpc18xx_wdt->clk_rate; in lpc18xx_wdt_probe()
267 lpc18xx_wdt->wdt_dev.timeout = min(lpc18xx_wdt->wdt_dev.max_timeout, in lpc18xx_wdt_probe()
270 spin_lock_init(&lpc18xx_wdt->lock); in lpc18xx_wdt_probe()
272 lpc18xx_wdt->wdt_dev.parent = dev; in lpc18xx_wdt_probe()
273 watchdog_set_drvdata(&lpc18xx_wdt->wdt_dev, lpc18xx_wdt); in lpc18xx_wdt_probe()
275 watchdog_init_timeout(&lpc18xx_wdt->wdt_dev, heartbeat, dev); in lpc18xx_wdt_probe()
279 timer_setup(&lpc18xx_wdt->timer, lpc18xx_wdt_timer_feed, 0); in lpc18xx_wdt_probe()
281 watchdog_set_nowayout(&lpc18xx_wdt->wdt_dev, nowayout); in lpc18xx_wdt_probe()
282 watchdog_set_restart_priority(&lpc18xx_wdt->wdt_dev, 128); in lpc18xx_wdt_probe()
286 watchdog_stop_on_reboot(&lpc18xx_wdt->wdt_dev); in lpc18xx_wdt_probe()
287 return devm_watchdog_register_device(dev, &lpc18xx_wdt->wdt_dev); in lpc18xx_wdt_probe()
294 dev_warn(&pdev->dev, "I quit now, hardware will probably reboot!\n"); in lpc18xx_wdt_remove()
295 del_timer_sync(&lpc18xx_wdt->timer); in lpc18xx_wdt_remove()
301 { .compatible = "nxp,lpc1850-wwdt" },
308 .name = "lpc18xx-wdt",
317 MODULE_DESCRIPTION("NXP LPC18xx Watchdog Timer Driver");