Lines Matching +full:wdt +full:- +full:enable +full:- +full:once
1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (C) 2008 Renaud CERRATO r.cerrato@til-technologies.fr
10 * The Watchdog Timer Mode Register can be only written to once. If the
40 #define wdt_read(wdt, field) \ argument
41 readl_relaxed((wdt)->base + (field))
43 writel_relaxed((val), (wdt)->base + (field))
52 #define secs_to_ticks(s) ((s) ? (((s) << 8) - 1) : 0)
77 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
88 unsigned long heartbeat; /* WDT heartbeat in jiffies */
98 struct at91wdt *wdt = (struct at91wdt *)dev_id; in wdt_interrupt() local
100 if (wdt_read(wdt, AT91_WDT_SR)) { in wdt_interrupt()
101 pr_crit("at91sam9 WDT software reset\n"); in wdt_interrupt()
112 static inline void at91_wdt_reset(struct at91wdt *wdt) in at91_wdt_reset() argument
114 wdt_write(wdt, AT91_WDT_CR, AT91_WDT_KEY | AT91_WDT_WDRSTT); in at91_wdt_reset()
122 struct at91wdt *wdt = from_timer(wdt, t, timer); in at91_ping() local
123 if (time_before(jiffies, wdt->next_heartbeat) || in at91_ping()
124 !watchdog_active(&wdt->wdd)) { in at91_ping()
125 at91_wdt_reset(wdt); in at91_ping()
126 mod_timer(&wdt->timer, jiffies + wdt->heartbeat); in at91_ping()
134 struct at91wdt *wdt = to_wdt(wdd); in at91_wdt_start() local
136 wdt->next_heartbeat = jiffies + wdd->timeout * HZ; in at91_wdt_start()
148 wdd->timeout = new_timeout; in at91_wdt_set_timeout()
152 static int at91_wdt_init(struct platform_device *pdev, struct at91wdt *wdt) in at91_wdt_init() argument
158 u32 mask = wdt->mr_mask; in at91_wdt_init()
161 struct device *dev = &pdev->dev; in at91_wdt_init()
163 tmp = wdt_read(wdt, AT91_WDT_MR); in at91_wdt_init()
164 if ((tmp & mask) != (wdt->mr & mask)) { in at91_wdt_init()
166 wdt_write(wdt, AT91_WDT_MR, wdt->mr); in at91_wdt_init()
167 tmp = wdt_read(wdt, AT91_WDT_MR); in at91_wdt_init()
172 if (wdt->mr & AT91_WDT_WDDIS) in at91_wdt_init()
175 return -EINVAL; in at91_wdt_init()
182 min_heartbeat = ticks_to_hz_roundup(value - delta); in at91_wdt_init()
188 return -EINVAL; in at91_wdt_init()
198 wdt->heartbeat = max_heartbeat / 4; in at91_wdt_init()
200 wdt->heartbeat = max_heartbeat / 2; in at91_wdt_init()
202 wdt->heartbeat = min_heartbeat; in at91_wdt_init()
208 if ((tmp & AT91_WDT_WDFIEN) && wdt->irq) { in at91_wdt_init()
209 err = devm_request_irq(dev, wdt->irq, wdt_interrupt, in at91_wdt_init()
211 pdev->name, wdt); in at91_wdt_init()
216 if ((tmp & wdt->mr_mask) != (wdt->mr & wdt->mr_mask)) in at91_wdt_init()
219 tmp & wdt->mr_mask, wdt->mr & wdt->mr_mask); in at91_wdt_init()
221 timer_setup(&wdt->timer, at91_ping, 0); in at91_wdt_init()
226 * - resetting it right now might trigger a watchdog fault reset in at91_wdt_init()
227 * - waiting for heartbeat time might lead to a watchdog timeout in at91_wdt_init()
230 mod_timer(&wdt->timer, jiffies + min_heartbeat); in at91_wdt_init()
233 if (watchdog_init_timeout(&wdt->wdd, 0, dev)) in at91_wdt_init()
234 watchdog_init_timeout(&wdt->wdd, heartbeat, dev); in at91_wdt_init()
235 watchdog_set_nowayout(&wdt->wdd, wdt->nowayout); in at91_wdt_init()
236 err = watchdog_register_device(&wdt->wdd); in at91_wdt_init()
240 wdt->next_heartbeat = jiffies + wdt->wdd.timeout * HZ; in at91_wdt_init()
245 del_timer(&wdt->timer); in at91_wdt_init()
265 static int of_at91wdt_init(struct device_node *np, struct at91wdt *wdt) in of_at91wdt_init() argument
272 wdt->irq = irq_of_parse_and_map(np, 0); in of_at91wdt_init()
273 if (!wdt->irq) in of_at91wdt_init()
274 dev_warn(wdt->wdd.parent, "failed to get IRQ from DT\n"); in of_at91wdt_init()
276 if (!of_property_read_u32_index(np, "atmel,max-heartbeat-sec", 0, in of_at91wdt_init()
281 if (!of_property_read_u32_index(np, "atmel,min-heartbeat-sec", in of_at91wdt_init()
284 min = max - 1; in of_at91wdt_init()
291 wdt->mr_mask = 0x3FFFFFFF; in of_at91wdt_init()
292 wdt->mr = 0; in of_at91wdt_init()
293 if (!of_property_read_string(np, "atmel,watchdog-type", &tmp) && in of_at91wdt_init()
295 wdt->mr |= AT91_WDT_WDFIEN; in of_at91wdt_init()
296 wdt->mr_mask &= ~AT91_WDT_WDRPROC; in of_at91wdt_init()
298 wdt->mr |= AT91_WDT_WDRSTEN; in of_at91wdt_init()
301 if (!of_property_read_string(np, "atmel,reset-type", &tmp) && in of_at91wdt_init()
303 wdt->mr |= AT91_WDT_WDRPROC; in of_at91wdt_init()
306 wdt->mr |= AT91_WDT_WDDIS; in of_at91wdt_init()
307 wdt->mr_mask &= AT91_WDT_WDDIS; in of_at91wdt_init()
310 if (of_property_read_bool(np, "atmel,idle-halt")) in of_at91wdt_init()
311 wdt->mr |= AT91_WDT_WDIDLEHLT; in of_at91wdt_init()
313 if (of_property_read_bool(np, "atmel,dbg-halt")) in of_at91wdt_init()
314 wdt->mr |= AT91_WDT_WDDBGHLT; in of_at91wdt_init()
316 wdt->mr |= max | ((max - min) << 16); in of_at91wdt_init()
321 static inline int of_at91wdt_init(struct device_node *np, struct at91wdt *wdt) in of_at91wdt_init() argument
330 struct at91wdt *wdt; in at91wdt_probe() local
332 wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); in at91wdt_probe()
333 if (!wdt) in at91wdt_probe()
334 return -ENOMEM; in at91wdt_probe()
336 wdt->mr = (WDT_HW_TIMEOUT * 256) | AT91_WDT_WDRSTEN | AT91_WDT_WDD | in at91wdt_probe()
338 wdt->mr_mask = 0x3FFFFFFF; in at91wdt_probe()
339 wdt->nowayout = nowayout; in at91wdt_probe()
340 wdt->wdd.parent = &pdev->dev; in at91wdt_probe()
341 wdt->wdd.info = &at91_wdt_info; in at91wdt_probe()
342 wdt->wdd.ops = &at91_wdt_ops; in at91wdt_probe()
343 wdt->wdd.timeout = WDT_HEARTBEAT; in at91wdt_probe()
344 wdt->wdd.min_timeout = 1; in at91wdt_probe()
345 wdt->wdd.max_timeout = 0xFFFF; in at91wdt_probe()
347 wdt->base = devm_platform_ioremap_resource(pdev, 0); in at91wdt_probe()
348 if (IS_ERR(wdt->base)) in at91wdt_probe()
349 return PTR_ERR(wdt->base); in at91wdt_probe()
351 wdt->sclk = devm_clk_get_enabled(&pdev->dev, NULL); in at91wdt_probe()
352 if (IS_ERR(wdt->sclk)) { in at91wdt_probe()
353 dev_err(&pdev->dev, "Could not enable slow clock\n"); in at91wdt_probe()
354 return PTR_ERR(wdt->sclk); in at91wdt_probe()
357 if (pdev->dev.of_node) { in at91wdt_probe()
358 err = of_at91wdt_init(pdev->dev.of_node, wdt); in at91wdt_probe()
363 err = at91_wdt_init(pdev, wdt); in at91wdt_probe()
367 platform_set_drvdata(pdev, wdt); in at91wdt_probe()
370 wdt->wdd.timeout, wdt->nowayout); in at91wdt_probe()
377 struct at91wdt *wdt = platform_get_drvdata(pdev); in at91wdt_remove() local
378 watchdog_unregister_device(&wdt->wdd); in at91wdt_remove()
381 del_timer(&wdt->timer); in at91wdt_remove()
386 { .compatible = "atmel,at91sam9260-wdt" },
403 MODULE_AUTHOR("Renaud CERRATO <r.cerrato@til-technologies.fr>");