Lines Matching +full:wdt +full:- +full:enable +full:- +full:once

1 // SPDX-License-Identifier: GPL-2.0+
3 * Cadence WDT driver - Used by Xilinx Zynq
5 * Copyright (C) 2010 - 2014 Xilinx, Inc.
21 /* Supports 1 - 516 sec */
59 "Watchdog cannot be stopped once started (default="
63 * struct cdns_wdt - Watchdog device structure
85 static inline void cdns_wdt_writereg(struct cdns_wdt *wdt, u32 offset, u32 val) in cdns_wdt_writereg() argument
87 writel_relaxed(val, wdt->regs + offset); in cdns_wdt_writereg()
92 /* Register Offsets for the WDT */
99 * Zero Mode Register - This register controls how the time out is indicated
102 #define CDNS_WDT_ZMR_WDEN_MASK 0x00000001 /* Enable the WDT */
103 #define CDNS_WDT_ZMR_RSTEN_MASK 0x00000002 /* Enable the reset output */
104 #define CDNS_WDT_ZMR_IRQEN_MASK 0x00000004 /* Enable IRQ output */
108 * Counter Control register - This register controls how fast the timer runs
115 * cdns_wdt_stop - Stop the watchdog.
126 struct cdns_wdt *wdt = watchdog_get_drvdata(wdd); in cdns_wdt_stop() local
128 spin_lock(&wdt->io_lock); in cdns_wdt_stop()
129 cdns_wdt_writereg(wdt, CDNS_WDT_ZMR_OFFSET, in cdns_wdt_stop()
131 spin_unlock(&wdt->io_lock); in cdns_wdt_stop()
137 * cdns_wdt_reload - Reload the watchdog timer (i.e. pat the watchdog).
147 struct cdns_wdt *wdt = watchdog_get_drvdata(wdd); in cdns_wdt_reload() local
149 spin_lock(&wdt->io_lock); in cdns_wdt_reload()
150 cdns_wdt_writereg(wdt, CDNS_WDT_RESTART_OFFSET, in cdns_wdt_reload()
152 spin_unlock(&wdt->io_lock); in cdns_wdt_reload()
158 * cdns_wdt_start - Enable and start the watchdog.
169 * Sets the WDT (WDEN bit) and either the Reset signal(RSTEN bit)
177 struct cdns_wdt *wdt = watchdog_get_drvdata(wdd); in cdns_wdt_start() local
180 unsigned long clock_f = clk_get_rate(wdt->clk); in cdns_wdt_start()
186 count = (wdd->timeout * (clock_f / wdt->prescaler)) / in cdns_wdt_start()
192 spin_lock(&wdt->io_lock); in cdns_wdt_start()
193 cdns_wdt_writereg(wdt, CDNS_WDT_ZMR_OFFSET, in cdns_wdt_start()
199 data = count | CDNS_WDT_REGISTER_ACCESS_KEY | wdt->ctrl_clksel; in cdns_wdt_start()
200 cdns_wdt_writereg(wdt, CDNS_WDT_CCR_OFFSET, data); in cdns_wdt_start()
205 if (wdt->rst) { in cdns_wdt_start()
212 cdns_wdt_writereg(wdt, CDNS_WDT_ZMR_OFFSET, data); in cdns_wdt_start()
213 cdns_wdt_writereg(wdt, CDNS_WDT_RESTART_OFFSET, in cdns_wdt_start()
215 spin_unlock(&wdt->io_lock); in cdns_wdt_start()
221 * cdns_wdt_settimeout - Set a new timeout value for the watchdog device.
233 wdd->timeout = new_time; in cdns_wdt_settimeout()
239 * cdns_wdt_irq_handler - Notifies of watchdog timeout.
252 dev_info(&pdev->dev, in cdns_wdt_irq_handler()
279 * cdns_wdt_probe - Probe call for the device.
288 struct device *dev = &pdev->dev; in cdns_wdt_probe()
291 struct cdns_wdt *wdt; in cdns_wdt_probe() local
294 wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); in cdns_wdt_probe()
295 if (!wdt) in cdns_wdt_probe()
296 return -ENOMEM; in cdns_wdt_probe()
298 cdns_wdt_device = &wdt->cdns_wdt_device; in cdns_wdt_probe()
299 cdns_wdt_device->info = &cdns_wdt_info; in cdns_wdt_probe()
300 cdns_wdt_device->ops = &cdns_wdt_ops; in cdns_wdt_probe()
301 cdns_wdt_device->timeout = CDNS_WDT_DEFAULT_TIMEOUT; in cdns_wdt_probe()
302 cdns_wdt_device->min_timeout = CDNS_WDT_MIN_TIMEOUT; in cdns_wdt_probe()
303 cdns_wdt_device->max_timeout = CDNS_WDT_MAX_TIMEOUT; in cdns_wdt_probe()
305 wdt->regs = devm_platform_ioremap_resource(pdev, 0); in cdns_wdt_probe()
306 if (IS_ERR(wdt->regs)) in cdns_wdt_probe()
307 return PTR_ERR(wdt->regs); in cdns_wdt_probe()
310 wdt->rst = of_property_read_bool(dev->of_node, "reset-on-timeout"); in cdns_wdt_probe()
312 if (!wdt->rst && irq >= 0) { in cdns_wdt_probe()
314 pdev->name, pdev); in cdns_wdt_probe()
324 cdns_wdt_device->parent = dev; in cdns_wdt_probe()
329 watchdog_set_drvdata(cdns_wdt_device, wdt); in cdns_wdt_probe()
331 wdt->clk = devm_clk_get_enabled(dev, NULL); in cdns_wdt_probe()
332 if (IS_ERR(wdt->clk)) in cdns_wdt_probe()
333 return dev_err_probe(dev, PTR_ERR(wdt->clk), in cdns_wdt_probe()
336 clock_f = clk_get_rate(wdt->clk); in cdns_wdt_probe()
338 wdt->prescaler = CDNS_WDT_PRESCALE_512; in cdns_wdt_probe()
339 wdt->ctrl_clksel = CDNS_WDT_PRESCALE_SELECT_512; in cdns_wdt_probe()
341 wdt->prescaler = CDNS_WDT_PRESCALE_4096; in cdns_wdt_probe()
342 wdt->ctrl_clksel = CDNS_WDT_PRESCALE_SELECT_4096; in cdns_wdt_probe()
345 spin_lock_init(&wdt->io_lock); in cdns_wdt_probe()
352 platform_set_drvdata(pdev, wdt); in cdns_wdt_probe()
355 cdns_wdt_device->timeout, nowayout ? ", nowayout" : ""); in cdns_wdt_probe()
361 * cdns_wdt_suspend - Stop the device.
368 struct cdns_wdt *wdt = dev_get_drvdata(dev); in cdns_wdt_suspend() local
370 if (watchdog_active(&wdt->cdns_wdt_device)) { in cdns_wdt_suspend()
371 cdns_wdt_stop(&wdt->cdns_wdt_device); in cdns_wdt_suspend()
372 clk_disable_unprepare(wdt->clk); in cdns_wdt_suspend()
379 * cdns_wdt_resume - Resume the device.
387 struct cdns_wdt *wdt = dev_get_drvdata(dev); in cdns_wdt_resume() local
389 if (watchdog_active(&wdt->cdns_wdt_device)) { in cdns_wdt_resume()
390 ret = clk_prepare_enable(wdt->clk); in cdns_wdt_resume()
392 dev_err(dev, "unable to enable clock\n"); in cdns_wdt_resume()
395 cdns_wdt_start(&wdt->cdns_wdt_device); in cdns_wdt_resume()
404 { .compatible = "cdns,wdt-r1p2", },
413 .name = "cdns-wdt",
422 MODULE_DESCRIPTION("Watchdog driver for Cadence WDT");