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

1 // SPDX-License-Identifier: GPL-2.0
14 * ---- -----
15 * Registers: 32-bit 16-bit
17 * Need to enable clk: No Yes
34 #define DRIVER_NAME "imx2-wdt"
37 #define IMX2_WDT_WCR_WT (0xFF << 8) /* -> Watchdog Timeout Field */
38 #define IMX2_WDT_WCR_WDA BIT(5) /* -> External Reset WDOG_B */
39 #define IMX2_WDT_WCR_SRS BIT(4) /* -> Software Reset Signal */
40 #define IMX2_WDT_WCR_WRE BIT(3) /* -> WDOG Reset Enable */
41 #define IMX2_WDT_WCR_WDE BIT(2) /* -> Watchdog Enable */
42 #define IMX2_WDT_WCR_WDZST BIT(0) /* -> Watchdog timer Suspend */
45 #define IMX2_WDT_SEQ1 0x5555 /* -> service sequence 1 */
46 #define IMX2_WDT_SEQ2 0xAAAA /* -> service sequence 2 */
49 #define IMX2_WDT_WRSR_TOUT BIT(1) /* -> Reset due to Timeout */
52 #define IMX2_WDT_WICR_WIE BIT(15) /* -> Interrupt Enable */
53 #define IMX2_WDT_WICR_WTIS BIT(14) /* -> Interrupt Status */
54 #define IMX2_WDT_WICR_WICT 0xFF /* -> Interrupt Count Timeout */
61 #define WDOG_SEC_TO_COUNT(s) ((s * 2 - 1) << 8)
74 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
99 /* Use internal reset or external - not both */ in imx2_wdt_restart()
100 if (wdev->ext_reset) in imx2_wdt_restart()
103 wcr_enable |= IMX2_WDT_WCR_WDA; /* do not assert ext-reset */ in imx2_wdt_restart()
106 regmap_write(wdev->regmap, IMX2_WDT_WCR, wcr_enable); in imx2_wdt_restart()
114 regmap_write(wdev->regmap, IMX2_WDT_WCR, wcr_enable); in imx2_wdt_restart()
115 regmap_write(wdev->regmap, IMX2_WDT_WCR, wcr_enable); in imx2_wdt_restart()
128 regmap_read(wdev->regmap, IMX2_WDT_WCR, &val); in imx2_wdt_setup()
130 /* Suspend timer in low power mode, write once-only */ in imx2_wdt_setup()
132 /* Strip the old watchdog Time-Out value */ in imx2_wdt_setup()
134 /* Generate internal chip-level reset if WDOG times out */ in imx2_wdt_setup()
135 if (!wdev->ext_reset) in imx2_wdt_setup()
137 /* Or if external-reset assert WDOG_B reset only on time-out */ in imx2_wdt_setup()
142 /* Set the watchdog's Time-Out value */ in imx2_wdt_setup()
143 val |= WDOG_SEC_TO_COUNT(wdog->timeout); in imx2_wdt_setup()
145 regmap_write(wdev->regmap, IMX2_WDT_WCR, val); in imx2_wdt_setup()
147 /* enable the watchdog */ in imx2_wdt_setup()
149 regmap_write(wdev->regmap, IMX2_WDT_WCR, val); in imx2_wdt_setup()
156 regmap_read(wdev->regmap, IMX2_WDT_WCR, &val); in imx2_wdt_is_running()
165 if (!wdev->clk_is_on) in imx2_wdt_ping()
168 regmap_write(wdev->regmap, IMX2_WDT_WSR, IMX2_WDT_SEQ1); in imx2_wdt_ping()
169 regmap_write(wdev->regmap, IMX2_WDT_WSR, IMX2_WDT_SEQ2); in imx2_wdt_ping()
178 regmap_update_bits(wdev->regmap, IMX2_WDT_WCR, IMX2_WDT_WCR_WT, in __imx2_wdt_set_timeout()
189 wdog->timeout = new_timeout; in imx2_wdt_set_timeout()
199 return -EINVAL; in imx2_wdt_set_pretimeout()
201 wdog->pretimeout = new_pretimeout; in imx2_wdt_set_pretimeout()
203 regmap_update_bits(wdev->regmap, IMX2_WDT_WICR, in imx2_wdt_set_pretimeout()
214 regmap_write_bits(wdev->regmap, IMX2_WDT_WICR, in imx2_wdt_isr()
227 imx2_wdt_set_timeout(wdog, wdog->timeout); in imx2_wdt_start()
231 set_bit(WDOG_HW_RUNNING, &wdog->status); in imx2_wdt_start()
259 struct device *dev = &pdev->dev; in imx2_wdt_probe()
268 return -ENOMEM; in imx2_wdt_probe()
274 wdev->regmap = devm_regmap_init_mmio_clk(dev, NULL, base, in imx2_wdt_probe()
276 if (IS_ERR(wdev->regmap)) { in imx2_wdt_probe()
278 return PTR_ERR(wdev->regmap); in imx2_wdt_probe()
281 wdev->clk = devm_clk_get(dev, NULL); in imx2_wdt_probe()
282 if (IS_ERR(wdev->clk)) { in imx2_wdt_probe()
284 return PTR_ERR(wdev->clk); in imx2_wdt_probe()
287 wdog = &wdev->wdog; in imx2_wdt_probe()
288 wdog->info = &imx2_wdt_info; in imx2_wdt_probe()
289 wdog->ops = &imx2_wdt_ops; in imx2_wdt_probe()
290 wdog->min_timeout = 1; in imx2_wdt_probe()
291 wdog->timeout = IMX2_WDT_DEFAULT_TIME; in imx2_wdt_probe()
292 wdog->max_hw_heartbeat_ms = IMX2_WDT_MAX_TIME * 1000; in imx2_wdt_probe()
293 wdog->parent = dev; in imx2_wdt_probe()
299 wdog->info = &imx2_wdt_pretimeout_info; in imx2_wdt_probe()
301 ret = clk_prepare_enable(wdev->clk); in imx2_wdt_probe()
305 ret = devm_add_action_or_reset(dev, imx2_wdt_action, wdev->clk); in imx2_wdt_probe()
309 wdev->clk_is_on = true; in imx2_wdt_probe()
311 regmap_read(wdev->regmap, IMX2_WDT_WRSR, &val); in imx2_wdt_probe()
312 wdog->bootstatus = val & IMX2_WDT_WRSR_TOUT ? WDIOF_CARDRESET : 0; in imx2_wdt_probe()
314 wdev->ext_reset = of_property_read_bool(dev->of_node, in imx2_wdt_probe()
315 "fsl,ext-reset-output"); in imx2_wdt_probe()
320 wdev->no_ping = !of_device_is_compatible(dev->of_node, "fsl,imx7d-wdt"); in imx2_wdt_probe()
326 if (wdev->no_ping) in imx2_wdt_probe()
330 imx2_wdt_set_timeout(wdog, wdog->timeout); in imx2_wdt_probe()
331 set_bit(WDOG_HW_RUNNING, &wdog->status); in imx2_wdt_probe()
339 regmap_write(wdev->regmap, IMX2_WDT_WMCR, 0); in imx2_wdt_probe()
356 dev_crit(&pdev->dev, "Device shutdown: Expect reboot!\n"); in imx2_wdt_shutdown()
360 /* Disable watchdog if it is active or non-active but still running */
369 * Don't update wdog->timeout, we'll restore the current value in imx2_wdt_suspend()
376 if (wdev->no_ping) { in imx2_wdt_suspend()
377 clk_disable_unprepare(wdev->clk); in imx2_wdt_suspend()
379 wdev->clk_is_on = false; in imx2_wdt_suspend()
385 /* Enable watchdog and configure it if necessary */
392 if (wdev->no_ping) { in imx2_wdt_resume()
393 ret = clk_prepare_enable(wdev->clk); in imx2_wdt_resume()
398 wdev->clk_is_on = true; in imx2_wdt_resume()
410 imx2_wdt_set_timeout(wdog, wdog->timeout); in imx2_wdt_resume()
421 { .compatible = "fsl,imx21-wdt", },
422 { .compatible = "fsl,imx7d-wdt", },