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

1 // SPDX-License-Identifier: GPL-2.0-only
30 #define INTERNAL_REGS_MASK ~(SZ_1M - 1)
70 struct watchdog_device wdt; member
84 dev->clk = clk_get(&pdev->dev, NULL); in orion_wdt_clock_init()
85 if (IS_ERR(dev->clk)) in orion_wdt_clock_init()
86 return PTR_ERR(dev->clk); in orion_wdt_clock_init()
87 ret = clk_prepare_enable(dev->clk); in orion_wdt_clock_init()
89 clk_put(dev->clk); in orion_wdt_clock_init()
93 dev->clk_rate = clk_get_rate(dev->clk); in orion_wdt_clock_init()
102 dev->clk = clk_get(&pdev->dev, NULL); in armada370_wdt_clock_init()
103 if (IS_ERR(dev->clk)) in armada370_wdt_clock_init()
104 return PTR_ERR(dev->clk); in armada370_wdt_clock_init()
105 ret = clk_prepare_enable(dev->clk); in armada370_wdt_clock_init()
107 clk_put(dev->clk); in armada370_wdt_clock_init()
112 atomic_io_modify(dev->reg + TIMER_CTRL, in armada370_wdt_clock_init()
116 dev->clk_rate = clk_get_rate(dev->clk) / WDT_A370_RATIO; in armada370_wdt_clock_init()
125 dev->clk = of_clk_get_by_name(pdev->dev.of_node, "fixed"); in armada375_wdt_clock_init()
126 if (!IS_ERR(dev->clk)) { in armada375_wdt_clock_init()
127 ret = clk_prepare_enable(dev->clk); in armada375_wdt_clock_init()
129 clk_put(dev->clk); in armada375_wdt_clock_init()
133 atomic_io_modify(dev->reg + TIMER_CTRL, in armada375_wdt_clock_init()
136 dev->clk_rate = clk_get_rate(dev->clk); in armada375_wdt_clock_init()
142 dev->clk = clk_get(&pdev->dev, NULL); in armada375_wdt_clock_init()
143 if (IS_ERR(dev->clk)) in armada375_wdt_clock_init()
144 return PTR_ERR(dev->clk); in armada375_wdt_clock_init()
146 ret = clk_prepare_enable(dev->clk); in armada375_wdt_clock_init()
148 clk_put(dev->clk); in armada375_wdt_clock_init()
152 atomic_io_modify(dev->reg + TIMER_CTRL, in armada375_wdt_clock_init()
155 dev->clk_rate = clk_get_rate(dev->clk) / WDT_A370_RATIO; in armada375_wdt_clock_init()
166 dev->clk = of_clk_get_by_name(pdev->dev.of_node, "fixed"); in armadaxp_wdt_clock_init()
167 if (IS_ERR(dev->clk)) in armadaxp_wdt_clock_init()
168 return PTR_ERR(dev->clk); in armadaxp_wdt_clock_init()
169 ret = clk_prepare_enable(dev->clk); in armadaxp_wdt_clock_init()
171 clk_put(dev->clk); in armadaxp_wdt_clock_init()
175 /* Fix the wdt and timer1 clock frequency to 25MHz */ in armadaxp_wdt_clock_init()
177 atomic_io_modify(dev->reg + TIMER_CTRL, val, val); in armadaxp_wdt_clock_init()
179 dev->clk_rate = clk_get_rate(dev->clk); in armadaxp_wdt_clock_init()
187 writel(dev->clk_rate * wdt_dev->timeout, in orion_wdt_ping()
188 dev->reg + dev->data->wdt_counter_offset); in orion_wdt_ping()
189 if (dev->wdt.info->options & WDIOF_PRETIMEOUT) in orion_wdt_ping()
190 writel(dev->clk_rate * (wdt_dev->timeout - wdt_dev->pretimeout), in orion_wdt_ping()
191 dev->reg + TIMER1_VAL_OFF); in orion_wdt_ping()
202 writel(dev->clk_rate * wdt_dev->timeout, in armada375_start()
203 dev->reg + dev->data->wdt_counter_offset); in armada375_start()
204 if (dev->wdt.info->options & WDIOF_PRETIMEOUT) in armada375_start()
205 writel(dev->clk_rate * (wdt_dev->timeout - wdt_dev->pretimeout), in armada375_start()
206 dev->reg + TIMER1_VAL_OFF); in armada375_start()
209 atomic_io_modify(dev->reg + TIMER_A370_STATUS, WDT_A370_EXPIRED, 0); in armada375_start()
211 /* Enable watchdog timer */ in armada375_start()
212 reg = dev->data->wdt_enable_bit; in armada375_start()
213 if (dev->wdt.info->options & WDIOF_PRETIMEOUT) in armada375_start()
215 atomic_io_modify(dev->reg + TIMER_CTRL, reg, reg); in armada375_start()
217 /* Enable reset on watchdog */ in armada375_start()
218 reg = readl(dev->rstout); in armada375_start()
219 reg |= dev->data->rstout_enable_bit; in armada375_start()
220 writel(reg, dev->rstout); in armada375_start()
222 atomic_io_modify(dev->rstout_mask, dev->data->rstout_mask_bit, 0); in armada375_start()
232 writel(dev->clk_rate * wdt_dev->timeout, in armada370_start()
233 dev->reg + dev->data->wdt_counter_offset); in armada370_start()
236 atomic_io_modify(dev->reg + TIMER_A370_STATUS, WDT_A370_EXPIRED, 0); in armada370_start()
238 /* Enable watchdog timer */ in armada370_start()
239 reg = dev->data->wdt_enable_bit; in armada370_start()
240 if (dev->wdt.info->options & WDIOF_PRETIMEOUT) in armada370_start()
242 atomic_io_modify(dev->reg + TIMER_CTRL, reg, reg); in armada370_start()
244 /* Enable reset on watchdog */ in armada370_start()
245 reg = readl(dev->rstout); in armada370_start()
246 reg |= dev->data->rstout_enable_bit; in armada370_start()
247 writel(reg, dev->rstout); in armada370_start()
256 writel(dev->clk_rate * wdt_dev->timeout, in orion_start()
257 dev->reg + dev->data->wdt_counter_offset); in orion_start()
259 /* Enable watchdog timer */ in orion_start()
260 atomic_io_modify(dev->reg + TIMER_CTRL, dev->data->wdt_enable_bit, in orion_start()
261 dev->data->wdt_enable_bit); in orion_start()
263 /* Enable reset on watchdog */ in orion_start()
264 atomic_io_modify(dev->rstout, dev->data->rstout_enable_bit, in orion_start()
265 dev->data->rstout_enable_bit); in orion_start()
274 /* There are some per-SoC quirks to handle */ in orion_wdt_start()
275 return dev->data->start(wdt_dev); in orion_wdt_start()
283 atomic_io_modify(dev->rstout, dev->data->rstout_enable_bit, 0); in orion_stop()
286 atomic_io_modify(dev->reg + TIMER_CTRL, dev->data->wdt_enable_bit, 0); in orion_stop()
297 atomic_io_modify(dev->rstout_mask, dev->data->rstout_mask_bit, in armada375_stop()
298 dev->data->rstout_mask_bit); in armada375_stop()
299 reg = readl(dev->rstout); in armada375_stop()
300 reg &= ~dev->data->rstout_enable_bit; in armada375_stop()
301 writel(reg, dev->rstout); in armada375_stop()
304 mask = dev->data->wdt_enable_bit; in armada375_stop()
305 if (wdt_dev->info->options & WDIOF_PRETIMEOUT) in armada375_stop()
307 atomic_io_modify(dev->reg + TIMER_CTRL, mask, 0); in armada375_stop()
318 reg = readl(dev->rstout); in armada370_stop()
319 reg &= ~dev->data->rstout_enable_bit; in armada370_stop()
320 writel(reg, dev->rstout); in armada370_stop()
323 mask = dev->data->wdt_enable_bit; in armada370_stop()
324 if (wdt_dev->info->options & WDIOF_PRETIMEOUT) in armada370_stop()
326 atomic_io_modify(dev->reg + TIMER_CTRL, mask, 0); in armada370_stop()
335 return dev->data->stop(wdt_dev); in orion_wdt_stop()
342 enabled = readl(dev->rstout) & dev->data->rstout_enable_bit; in orion_enabled()
343 running = readl(dev->reg + TIMER_CTRL) & dev->data->wdt_enable_bit; in orion_enabled()
352 masked = readl(dev->rstout_mask) & dev->data->rstout_mask_bit; in armada375_enabled()
353 enabled = readl(dev->rstout) & dev->data->rstout_enable_bit; in armada375_enabled()
354 running = readl(dev->reg + TIMER_CTRL) & dev->data->wdt_enable_bit; in armada375_enabled()
363 return dev->data->enabled(dev); in orion_wdt_enabled()
369 return readl(dev->reg + dev->data->wdt_counter_offset) / dev->clk_rate; in orion_wdt_get_timeleft()
395 atomic_io_modify(dev->reg + TIMER_A370_STATUS, in orion_wdt_pre_irq()
397 watchdog_notify_pretimeout(&dev->wdt); in orion_wdt_pre_irq()
415 return devm_ioremap(&pdev->dev, res->start, in orion_wdt_ioremap_rstout()
421 return devm_ioremap(&pdev->dev, rstout, 0x4); in orion_wdt_ioremap_rstout()
478 .compatible = "marvell,orion-wdt",
482 .compatible = "marvell,armada-370-wdt",
486 .compatible = "marvell,armada-xp-wdt",
490 .compatible = "marvell,armada-375-wdt",
494 .compatible = "marvell,armada-380-wdt",
504 struct device_node *node = pdev->dev.of_node; in orion_wdt_get_regs()
509 return -ENODEV; in orion_wdt_get_regs()
510 dev->reg = devm_ioremap(&pdev->dev, res->start, in orion_wdt_get_regs()
512 if (!dev->reg) in orion_wdt_get_regs()
513 return -ENOMEM; in orion_wdt_get_regs()
516 if (of_device_is_compatible(node, "marvell,orion-wdt")) { in orion_wdt_get_regs()
518 dev->rstout = orion_wdt_ioremap_rstout(pdev, res->start & in orion_wdt_get_regs()
520 if (!dev->rstout) in orion_wdt_get_regs()
521 return -ENODEV; in orion_wdt_get_regs()
523 } else if (of_device_is_compatible(node, "marvell,armada-370-wdt") || in orion_wdt_get_regs()
524 of_device_is_compatible(node, "marvell,armada-xp-wdt")) { in orion_wdt_get_regs()
527 dev->rstout = devm_platform_ioremap_resource(pdev, 1); in orion_wdt_get_regs()
528 if (IS_ERR(dev->rstout)) in orion_wdt_get_regs()
529 return PTR_ERR(dev->rstout); in orion_wdt_get_regs()
531 } else if (of_device_is_compatible(node, "marvell,armada-375-wdt") || in orion_wdt_get_regs()
532 of_device_is_compatible(node, "marvell,armada-380-wdt")) { in orion_wdt_get_regs()
535 dev->rstout = devm_platform_ioremap_resource(pdev, 1); in orion_wdt_get_regs()
536 if (IS_ERR(dev->rstout)) in orion_wdt_get_regs()
537 return PTR_ERR(dev->rstout); in orion_wdt_get_regs()
541 return -ENODEV; in orion_wdt_get_regs()
542 dev->rstout_mask = devm_ioremap(&pdev->dev, res->start, in orion_wdt_get_regs()
544 if (!dev->rstout_mask) in orion_wdt_get_regs()
545 return -ENOMEM; in orion_wdt_get_regs()
548 return -ENODEV; in orion_wdt_get_regs()
561 dev = devm_kzalloc(&pdev->dev, sizeof(struct orion_watchdog), in orion_wdt_probe()
564 return -ENOMEM; in orion_wdt_probe()
566 match = of_match_device(orion_wdt_of_match_table, &pdev->dev); in orion_wdt_probe()
571 dev->wdt.info = &orion_wdt_info; in orion_wdt_probe()
572 dev->wdt.ops = &orion_wdt_ops; in orion_wdt_probe()
573 dev->wdt.min_timeout = 1; in orion_wdt_probe()
574 dev->data = match->data; in orion_wdt_probe()
580 ret = dev->data->clock_init(pdev, dev); in orion_wdt_probe()
582 dev_err(&pdev->dev, "cannot initialize clock\n"); in orion_wdt_probe()
586 wdt_max_duration = WDT_MAX_CYCLE_COUNT / dev->clk_rate; in orion_wdt_probe()
588 dev->wdt.timeout = wdt_max_duration; in orion_wdt_probe()
589 dev->wdt.max_timeout = wdt_max_duration; in orion_wdt_probe()
590 dev->wdt.parent = &pdev->dev; in orion_wdt_probe()
591 watchdog_init_timeout(&dev->wdt, heartbeat, &pdev->dev); in orion_wdt_probe()
593 platform_set_drvdata(pdev, &dev->wdt); in orion_wdt_probe()
594 watchdog_set_drvdata(&dev->wdt, dev); in orion_wdt_probe()
599 * removed and re-inserted, or if the bootloader explicitly in orion_wdt_probe()
602 if (!orion_wdt_enabled(&dev->wdt)) in orion_wdt_probe()
603 orion_wdt_stop(&dev->wdt); in orion_wdt_probe()
605 set_bit(WDOG_HW_RUNNING, &dev->wdt.status); in orion_wdt_probe()
614 ret = devm_request_irq(&pdev->dev, irq, orion_wdt_irq, 0, in orion_wdt_probe()
615 pdev->name, dev); in orion_wdt_probe()
617 dev_err(&pdev->dev, "failed to request IRQ\n"); in orion_wdt_probe()
626 ret = devm_request_irq(&pdev->dev, irq, orion_wdt_pre_irq, in orion_wdt_probe()
627 0, pdev->name, dev); in orion_wdt_probe()
629 dev_err(&pdev->dev, "failed to request IRQ\n"); in orion_wdt_probe()
635 watchdog_set_nowayout(&dev->wdt, nowayout); in orion_wdt_probe()
636 ret = watchdog_register_device(&dev->wdt); in orion_wdt_probe()
641 dev->wdt.timeout, nowayout ? ", nowayout" : ""); in orion_wdt_probe()
645 clk_disable_unprepare(dev->clk); in orion_wdt_probe()
646 clk_put(dev->clk); in orion_wdt_probe()
656 clk_disable_unprepare(dev->clk); in orion_wdt_remove()
657 clk_put(dev->clk); in orion_wdt_remove()
685 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="