Lines Matching +full:lpc1850 +full:- +full:wwdt
1 // SPDX-License-Identifier: GPL-2.0-only
8 * -----
9 * The Watchdog consists of a fixed divide-by-4 clock pre-scaler and a 24-bit
35 /* Clock pre-scaler */
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()
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()
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()
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()
203 struct device *dev = &pdev->dev; in lpc18xx_wdt_probe()
207 return -ENOMEM; in lpc18xx_wdt_probe()
209 lpc18xx_wdt->base = devm_platform_ioremap_resource(pdev, 0); in lpc18xx_wdt_probe()
210 if (IS_ERR(lpc18xx_wdt->base)) in lpc18xx_wdt_probe()
211 return PTR_ERR(lpc18xx_wdt->base); in lpc18xx_wdt_probe()
213 lpc18xx_wdt->reg_clk = devm_clk_get_enabled(dev, "reg"); in lpc18xx_wdt_probe()
214 if (IS_ERR(lpc18xx_wdt->reg_clk)) { in lpc18xx_wdt_probe()
216 return PTR_ERR(lpc18xx_wdt->reg_clk); in lpc18xx_wdt_probe()
219 lpc18xx_wdt->wdt_clk = devm_clk_get_enabled(dev, "wdtclk"); in lpc18xx_wdt_probe()
220 if (IS_ERR(lpc18xx_wdt->wdt_clk)) { in lpc18xx_wdt_probe()
222 return PTR_ERR(lpc18xx_wdt->wdt_clk); in lpc18xx_wdt_probe()
226 lpc18xx_wdt->clk_rate = clk_get_rate(lpc18xx_wdt->wdt_clk); in lpc18xx_wdt_probe()
227 if (lpc18xx_wdt->clk_rate == 0) { in lpc18xx_wdt_probe()
229 return -EINVAL; in lpc18xx_wdt_probe()
232 lpc18xx_wdt->wdt_dev.info = &lpc18xx_wdt_info; in lpc18xx_wdt_probe()
233 lpc18xx_wdt->wdt_dev.ops = &lpc18xx_wdt_ops; in lpc18xx_wdt_probe()
235 lpc18xx_wdt->wdt_dev.min_timeout = DIV_ROUND_UP(LPC18XX_WDT_TC_MIN * in lpc18xx_wdt_probe()
236 LPC18XX_WDT_CLK_DIV, lpc18xx_wdt->clk_rate); in lpc18xx_wdt_probe()
238 lpc18xx_wdt->wdt_dev.max_timeout = (LPC18XX_WDT_TC_MAX * in lpc18xx_wdt_probe()
239 LPC18XX_WDT_CLK_DIV) / lpc18xx_wdt->clk_rate; in lpc18xx_wdt_probe()
241 lpc18xx_wdt->wdt_dev.timeout = min(lpc18xx_wdt->wdt_dev.max_timeout, in lpc18xx_wdt_probe()
244 spin_lock_init(&lpc18xx_wdt->lock); in lpc18xx_wdt_probe()
246 lpc18xx_wdt->wdt_dev.parent = dev; in lpc18xx_wdt_probe()
247 watchdog_set_drvdata(&lpc18xx_wdt->wdt_dev, lpc18xx_wdt); in lpc18xx_wdt_probe()
249 watchdog_init_timeout(&lpc18xx_wdt->wdt_dev, heartbeat, dev); in lpc18xx_wdt_probe()
253 timer_setup(&lpc18xx_wdt->timer, lpc18xx_wdt_timer_feed, 0); in lpc18xx_wdt_probe()
255 watchdog_set_nowayout(&lpc18xx_wdt->wdt_dev, nowayout); in lpc18xx_wdt_probe()
256 watchdog_set_restart_priority(&lpc18xx_wdt->wdt_dev, 128); in lpc18xx_wdt_probe()
260 watchdog_stop_on_reboot(&lpc18xx_wdt->wdt_dev); in lpc18xx_wdt_probe()
261 return devm_watchdog_register_device(dev, &lpc18xx_wdt->wdt_dev); in lpc18xx_wdt_probe()
268 dev_warn(&pdev->dev, "I quit now, hardware will probably reboot!\n"); in lpc18xx_wdt_remove()
269 del_timer_sync(&lpc18xx_wdt->timer); in lpc18xx_wdt_remove()
273 { .compatible = "nxp,lpc1850-wwdt" },
280 .name = "lpc18xx-wdt",