Lines Matching +full:j7 +full:- +full:rti +full:- +full:wdt
1 // SPDX-License-Identifier: GPL-2.0
3 * Watchdog driver for the K3 RTI module
5 * (c) Copyright 2019-2020 Texas Instruments Inc.
58 * struct to hold data for each WDT device
59 * @base - base io address of WD device
60 * @freq - source clock frequency of WDT
61 * @wdd - hold watchdog device as is in WDT core
72 struct rti_wdt_device *wdt = watchdog_get_drvdata(wdd); in rti_wdt_start() local
75 timer_margin = (u64)wdd->timeout * wdt->freq; in rti_wdt_start()
79 writel_relaxed(timer_margin, wdt->base + RTIDWDPRLD); in rti_wdt_start()
82 * RTI only supports a windowed mode, where the watchdog can only in rti_wdt_start()
88 wdd->min_hw_heartbeat_ms = 500 * wdd->timeout; in rti_wdt_start()
90 /* Generate NMI when wdt expires */ in rti_wdt_start()
91 writel_relaxed(RTIWWDRX_NMI, wdt->base + RTIWWDRXCTRL); in rti_wdt_start()
94 writel_relaxed(RTIWWDSIZE_50P, wdt->base + RTIWWDSIZECTRL); in rti_wdt_start()
96 readl_relaxed(wdt->base + RTIWWDSIZECTRL); in rti_wdt_start()
99 writel_relaxed(WDENABLE_KEY, wdt->base + RTIDWDCTRL); in rti_wdt_start()
105 struct rti_wdt_device *wdt = watchdog_get_drvdata(wdd); in rti_wdt_ping() local
108 writel_relaxed(WDKEY_SEQ0, wdt->base + RTIWDKEY); in rti_wdt_ping()
110 writel_relaxed(WDKEY_SEQ1, wdt->base + RTIWDKEY); in rti_wdt_ping()
118 * RTI only supports a windowed mode, where the watchdog can only in rti_wdt_setup_hw_hb()
126 wdd->min_hw_heartbeat_ms = 500 * heartbeat; in rti_wdt_setup_hw_hb()
131 wdd->min_hw_heartbeat_ms = 750 * heartbeat; in rti_wdt_setup_hw_hb()
136 wdd->min_hw_heartbeat_ms = 875 * heartbeat; in rti_wdt_setup_hw_hb()
141 wdd->min_hw_heartbeat_ms = 935 * heartbeat; in rti_wdt_setup_hw_hb()
146 wdd->min_hw_heartbeat_ms = 969 * heartbeat; in rti_wdt_setup_hw_hb()
150 return -EINVAL; in rti_wdt_setup_hw_hb()
160 struct rti_wdt_device *wdt = watchdog_get_drvdata(wdd); in rti_wdt_get_timeleft_ms() local
163 val = readl_relaxed(wdt->base + RTIWDSTATUS); in rti_wdt_get_timeleft_ms()
167 timer_counter = readl_relaxed(wdt->base + RTIDWDCNTR); in rti_wdt_get_timeleft_ms()
171 do_div(timer_counter, wdt->freq); in rti_wdt_get_timeleft_ms()
183 .identity = "K3 RTI Watchdog",
196 struct device *dev = &pdev->dev; in rti_wdt_probe()
198 struct rti_wdt_device *wdt; in rti_wdt_probe() local
202 wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); in rti_wdt_probe()
203 if (!wdt) in rti_wdt_probe()
204 return -ENOMEM; in rti_wdt_probe()
210 wdt->freq = clk_get_rate(clk); in rti_wdt_probe()
214 if (!wdt->freq) { in rti_wdt_probe()
216 return -EINVAL; in rti_wdt_probe()
224 if (wdt->freq < 32768) in rti_wdt_probe()
225 wdt->freq = wdt->freq * 9 / 10; in rti_wdt_probe()
230 pm_runtime_disable(&pdev->dev); in rti_wdt_probe()
234 platform_set_drvdata(pdev, wdt); in rti_wdt_probe()
236 wdd = &wdt->wdd; in rti_wdt_probe()
237 wdd->info = &rti_wdt_info; in rti_wdt_probe()
238 wdd->ops = &rti_wdt_ops; in rti_wdt_probe()
239 wdd->min_timeout = 1; in rti_wdt_probe()
240 wdd->max_hw_heartbeat_ms = (WDT_PRELOAD_MAX << WDT_PRELOAD_SHIFT) / in rti_wdt_probe()
241 wdt->freq * 1000; in rti_wdt_probe()
242 wdd->parent = dev; in rti_wdt_probe()
244 watchdog_set_drvdata(wdd, wdt); in rti_wdt_probe()
248 wdt->base = devm_platform_ioremap_resource(pdev, 0); in rti_wdt_probe()
249 if (IS_ERR(wdt->base)) { in rti_wdt_probe()
250 ret = PTR_ERR(wdt->base); in rti_wdt_probe()
254 if (readl(wdt->base + RTIDWDCTRL) == WDENABLE_KEY) { in rti_wdt_probe()
260 set_bit(WDOG_HW_RUNNING, &wdd->status); in rti_wdt_probe()
262 heartbeat_ms = readl(wdt->base + RTIDWDPRLD); in rti_wdt_probe()
265 do_div(heartbeat_ms, wdt->freq); in rti_wdt_probe()
273 wsize = readl(wdt->base + RTIWWDSIZECTRL); in rti_wdt_probe()
280 last_ping = heartbeat_ms - time_left_ms; in rti_wdt_probe()
301 pm_runtime_put_sync(&pdev->dev); in rti_wdt_probe()
302 pm_runtime_disable(&pdev->dev); in rti_wdt_probe()
309 struct rti_wdt_device *wdt = platform_get_drvdata(pdev); in rti_wdt_remove() local
311 watchdog_unregister_device(&wdt->wdd); in rti_wdt_remove()
312 pm_runtime_put(&pdev->dev); in rti_wdt_remove()
313 pm_runtime_disable(&pdev->dev); in rti_wdt_remove()
319 { .compatible = "ti,j7-rti-wdt", },
326 .name = "rti-wdt",
335 MODULE_AUTHOR("Tero Kristo <t-kristo@ti.com>");
336 MODULE_DESCRIPTION("K3 RTI Watchdog Driver");
345 MODULE_ALIAS("platform:rti-wdt");