Lines Matching full:wdt
51 #define wdt_enabled (!(wdt->mr & AT91_WDT_WDDIS))
53 #define wdt_read(wdt, field) \ argument
54 readl_relaxed((wdt)->reg_base + (field))
59 static void wdt_write(struct sama5d4_wdt *wdt, u32 field, u32 val) in wdt_write() argument
66 while (time_before(jiffies, wdt->last_ping + WDT_DELAY)) in wdt_write()
68 writel_relaxed(val, wdt->reg_base + field); in wdt_write()
69 wdt->last_ping = jiffies; in wdt_write()
72 static void wdt_write_nosleep(struct sama5d4_wdt *wdt, u32 field, u32 val) in wdt_write_nosleep() argument
74 if (time_before(jiffies, wdt->last_ping + WDT_DELAY)) in wdt_write_nosleep()
76 writel_relaxed(val, wdt->reg_base + field); in wdt_write_nosleep()
77 wdt->last_ping = jiffies; in wdt_write_nosleep()
82 struct sama5d4_wdt *wdt = watchdog_get_drvdata(wdd); in sama5d4_wdt_start() local
84 if (wdt->sam9x60_support) { in sama5d4_wdt_start()
85 writel_relaxed(wdt->ir, wdt->reg_base + AT91_SAM9X60_IER); in sama5d4_wdt_start()
86 wdt->mr &= ~AT91_SAM9X60_WDDIS; in sama5d4_wdt_start()
88 wdt->mr &= ~AT91_WDT_WDDIS; in sama5d4_wdt_start()
90 wdt_write(wdt, AT91_WDT_MR, wdt->mr); in sama5d4_wdt_start()
97 struct sama5d4_wdt *wdt = watchdog_get_drvdata(wdd); in sama5d4_wdt_stop() local
99 if (wdt->sam9x60_support) { in sama5d4_wdt_stop()
100 writel_relaxed(wdt->ir, wdt->reg_base + AT91_SAM9X60_IDR); in sama5d4_wdt_stop()
101 wdt->mr |= AT91_SAM9X60_WDDIS; in sama5d4_wdt_stop()
103 wdt->mr |= AT91_WDT_WDDIS; in sama5d4_wdt_stop()
105 wdt_write(wdt, AT91_WDT_MR, wdt->mr); in sama5d4_wdt_stop()
112 struct sama5d4_wdt *wdt = watchdog_get_drvdata(wdd); in sama5d4_wdt_ping() local
114 wdt_write(wdt, AT91_WDT_CR, AT91_WDT_KEY | AT91_WDT_WDRSTT); in sama5d4_wdt_ping()
122 struct sama5d4_wdt *wdt = watchdog_get_drvdata(wdd); in sama5d4_wdt_set_timeout() local
125 if (wdt->sam9x60_support) { in sama5d4_wdt_set_timeout()
126 wdt_write(wdt, AT91_SAM9X60_WLR, in sama5d4_wdt_set_timeout()
133 wdt->mr &= ~AT91_WDT_WDV; in sama5d4_wdt_set_timeout()
134 wdt->mr |= AT91_WDT_SET_WDV(value); in sama5d4_wdt_set_timeout()
144 wdt_write(wdt, AT91_WDT_MR, wdt->mr & ~AT91_WDT_WDDIS); in sama5d4_wdt_set_timeout()
166 struct sama5d4_wdt *wdt = platform_get_drvdata(dev_id); in sama5d4_wdt_irq_handler() local
169 if (wdt->sam9x60_support) in sama5d4_wdt_irq_handler()
170 reg = wdt_read(wdt, AT91_SAM9X60_ISR); in sama5d4_wdt_irq_handler()
172 reg = wdt_read(wdt, AT91_WDT_SR); in sama5d4_wdt_irq_handler()
183 static int of_sama5d4_wdt_init(struct device_node *np, struct sama5d4_wdt *wdt) in of_sama5d4_wdt_init() argument
187 if (wdt->sam9x60_support) in of_sama5d4_wdt_init()
188 wdt->mr = AT91_SAM9X60_WDDIS; in of_sama5d4_wdt_init()
190 wdt->mr = AT91_WDT_WDDIS; in of_sama5d4_wdt_init()
194 wdt->need_irq = true; in of_sama5d4_wdt_init()
197 wdt->mr |= AT91_WDT_WDIDLEHLT; in of_sama5d4_wdt_init()
200 wdt->mr |= AT91_WDT_WDDBGHLT; in of_sama5d4_wdt_init()
205 static int sama5d4_wdt_init(struct sama5d4_wdt *wdt) in sama5d4_wdt_init() argument
217 reg = wdt_read(wdt, AT91_WDT_MR); in sama5d4_wdt_init()
218 if (wdt->sam9x60_support && (!(reg & AT91_SAM9X60_WDDIS))) in sama5d4_wdt_init()
219 wdt_write_nosleep(wdt, AT91_WDT_MR, in sama5d4_wdt_init()
221 else if (!wdt->sam9x60_support && in sama5d4_wdt_init()
223 wdt_write_nosleep(wdt, AT91_WDT_MR, in sama5d4_wdt_init()
227 if (wdt->sam9x60_support) { in sama5d4_wdt_init()
228 if (wdt->need_irq) in sama5d4_wdt_init()
229 wdt->ir = AT91_SAM9X60_PERINT; in sama5d4_wdt_init()
231 wdt->mr |= AT91_SAM9X60_PERIODRST; in sama5d4_wdt_init()
233 wdt_write(wdt, AT91_SAM9X60_IER, wdt->ir); in sama5d4_wdt_init()
234 wdt_write(wdt, AT91_SAM9X60_WLR, AT91_SAM9X60_SET_COUNTER(val)); in sama5d4_wdt_init()
236 wdt->mr |= AT91_WDT_SET_WDD(WDT_SEC2TICKS(MAX_WDT_TIMEOUT)); in sama5d4_wdt_init()
237 wdt->mr |= AT91_WDT_SET_WDV(val); in sama5d4_wdt_init()
239 if (wdt->need_irq) in sama5d4_wdt_init()
240 wdt->mr |= AT91_WDT_WDFIEN; in sama5d4_wdt_init()
242 wdt->mr |= AT91_WDT_WDRSTEN; in sama5d4_wdt_init()
245 wdt_write_nosleep(wdt, AT91_WDT_MR, wdt->mr); in sama5d4_wdt_init()
254 struct sama5d4_wdt *wdt; in sama5d4_wdt_probe() local
260 wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); in sama5d4_wdt_probe()
261 if (!wdt) in sama5d4_wdt_probe()
264 wdd = &wdt->wdd; in sama5d4_wdt_probe()
270 wdt->last_ping = jiffies; in sama5d4_wdt_probe()
272 if (of_device_is_compatible(dev->of_node, "microchip,sam9x60-wdt") || in sama5d4_wdt_probe()
273 of_device_is_compatible(dev->of_node, "microchip,sama7g5-wdt")) in sama5d4_wdt_probe()
274 wdt->sam9x60_support = true; in sama5d4_wdt_probe()
276 watchdog_set_drvdata(wdd, wdt); in sama5d4_wdt_probe()
282 wdt->reg_base = regs; in sama5d4_wdt_probe()
284 ret = of_sama5d4_wdt_init(dev->of_node, wdt); in sama5d4_wdt_probe()
288 if (wdt->need_irq) { in sama5d4_wdt_probe()
292 wdt->need_irq = false; in sama5d4_wdt_probe()
296 if (wdt->need_irq) { in sama5d4_wdt_probe()
308 reg = wdt_read(wdt, AT91_WDT_MR); in sama5d4_wdt_probe()
310 wdt->mr &= ~AT91_WDT_WDDIS; in sama5d4_wdt_probe()
314 ret = sama5d4_wdt_init(wdt); in sama5d4_wdt_probe()
325 platform_set_drvdata(pdev, wdt); in sama5d4_wdt_probe()
335 .compatible = "atmel,sama5d4-wdt",
338 .compatible = "microchip,sam9x60-wdt",
341 .compatible = "microchip,sama7g5-wdt",
350 struct sama5d4_wdt *wdt = dev_get_drvdata(dev); in sama5d4_wdt_suspend_late() local
352 if (watchdog_active(&wdt->wdd)) in sama5d4_wdt_suspend_late()
353 sama5d4_wdt_stop(&wdt->wdd); in sama5d4_wdt_suspend_late()
360 struct sama5d4_wdt *wdt = dev_get_drvdata(dev); in sama5d4_wdt_resume_early() local
367 sama5d4_wdt_init(wdt); in sama5d4_wdt_resume_early()
369 if (watchdog_active(&wdt->wdd)) in sama5d4_wdt_resume_early()
370 sama5d4_wdt_start(&wdt->wdd); in sama5d4_wdt_resume_early()