Lines Matching full:wdt
2 * drivers/char/watchdog/sp805-wdt.c
36 #define MODULE_NAME "sp805-wdt"
57 * struct sp805_wdt: sp805 wdt device structure
60 * @base: base address of wdt
61 * @clk: clock structure of wdt
62 * @adev: amba device structure of wdt
63 * @status: current status of wdt
81 /* returns true if wdt is running; otherwise returns false */
84 struct sp805_wdt *wdt = watchdog_get_drvdata(wdd); in wdt_is_running() local
85 u32 wdtcontrol = readl_relaxed(wdt->base + WDTCONTROL); in wdt_is_running()
93 struct sp805_wdt *wdt = watchdog_get_drvdata(wdd); in wdt_setload() local
96 rate = wdt->rate; in wdt_setload()
109 spin_lock(&wdt->lock); in wdt_setload()
110 wdt->load_val = load; in wdt_setload()
113 spin_unlock(&wdt->lock); in wdt_setload()
121 struct sp805_wdt *wdt = watchdog_get_drvdata(wdd); in wdt_timeleft() local
124 spin_lock(&wdt->lock); in wdt_timeleft()
125 load = readl_relaxed(wdt->base + WDTVALUE); in wdt_timeleft()
128 if (!(readl_relaxed(wdt->base + WDTRIS) & INT_MASK)) in wdt_timeleft()
129 load += wdt->load_val + 1; in wdt_timeleft()
130 spin_unlock(&wdt->lock); in wdt_timeleft()
132 return div_u64(load, wdt->rate); in wdt_timeleft()
138 struct sp805_wdt *wdt = watchdog_get_drvdata(wdd); in wdt_restart() local
140 writel_relaxed(UNLOCK, wdt->base + WDTLOCK); in wdt_restart()
141 writel_relaxed(0, wdt->base + WDTCONTROL); in wdt_restart()
142 writel_relaxed(0, wdt->base + WDTLOAD); in wdt_restart()
143 writel_relaxed(INT_ENABLE | RESET_ENABLE, wdt->base + WDTCONTROL); in wdt_restart()
146 readl_relaxed(wdt->base + WDTLOCK); in wdt_restart()
153 struct sp805_wdt *wdt = watchdog_get_drvdata(wdd); in wdt_config() local
158 ret = clk_prepare_enable(wdt->clk); in wdt_config()
160 dev_err(&wdt->adev->dev, "clock enable fail"); in wdt_config()
165 spin_lock(&wdt->lock); in wdt_config()
167 writel_relaxed(UNLOCK, wdt->base + WDTLOCK); in wdt_config()
168 writel_relaxed(wdt->load_val, wdt->base + WDTLOAD); in wdt_config()
169 writel_relaxed(INT_MASK, wdt->base + WDTINTCLR); in wdt_config()
172 writel_relaxed(INT_ENABLE | RESET_ENABLE, wdt->base + in wdt_config()
175 writel_relaxed(LOCK, wdt->base + WDTLOCK); in wdt_config()
178 readl_relaxed(wdt->base + WDTLOCK); in wdt_config()
179 spin_unlock(&wdt->lock); in wdt_config()
198 struct sp805_wdt *wdt = watchdog_get_drvdata(wdd); in wdt_disable() local
200 spin_lock(&wdt->lock); in wdt_disable()
202 writel_relaxed(UNLOCK, wdt->base + WDTLOCK); in wdt_disable()
203 writel_relaxed(0, wdt->base + WDTCONTROL); in wdt_disable()
204 writel_relaxed(LOCK, wdt->base + WDTLOCK); in wdt_disable()
207 readl_relaxed(wdt->base + WDTLOCK); in wdt_disable()
208 spin_unlock(&wdt->lock); in wdt_disable()
210 clk_disable_unprepare(wdt->clk); in wdt_disable()
233 struct sp805_wdt *wdt; in sp805_wdt_probe() local
236 wdt = devm_kzalloc(&adev->dev, sizeof(*wdt), GFP_KERNEL); in sp805_wdt_probe()
237 if (!wdt) { in sp805_wdt_probe()
242 wdt->base = devm_ioremap_resource(&adev->dev, &adev->res); in sp805_wdt_probe()
243 if (IS_ERR(wdt->base)) in sp805_wdt_probe()
244 return PTR_ERR(wdt->base); in sp805_wdt_probe()
247 wdt->clk = devm_clk_get(&adev->dev, NULL); in sp805_wdt_probe()
248 if (IS_ERR(wdt->clk)) { in sp805_wdt_probe()
250 return PTR_ERR(wdt->clk); in sp805_wdt_probe()
252 wdt->rate = clk_get_rate(wdt->clk); in sp805_wdt_probe()
260 &wdt->rate); in sp805_wdt_probe()
261 if (!wdt->rate) { in sp805_wdt_probe()
267 wdt->adev = adev; in sp805_wdt_probe()
268 wdt->wdd.info = &wdt_info; in sp805_wdt_probe()
269 wdt->wdd.ops = &wdt_ops; in sp805_wdt_probe()
270 wdt->wdd.parent = &adev->dev; in sp805_wdt_probe()
272 spin_lock_init(&wdt->lock); in sp805_wdt_probe()
273 watchdog_set_nowayout(&wdt->wdd, nowayout); in sp805_wdt_probe()
274 watchdog_set_drvdata(&wdt->wdd, wdt); in sp805_wdt_probe()
275 watchdog_set_restart_priority(&wdt->wdd, 128); in sp805_wdt_probe()
281 wdt->wdd.timeout = DEFAULT_TIMEOUT; in sp805_wdt_probe()
282 watchdog_init_timeout(&wdt->wdd, 0, &adev->dev); in sp805_wdt_probe()
283 wdt_setload(&wdt->wdd, wdt->wdd.timeout); in sp805_wdt_probe()
286 * If HW is already running, enable/reset the wdt and set the running in sp805_wdt_probe()
287 * bit to tell the wdt subsystem in sp805_wdt_probe()
289 if (wdt_is_running(&wdt->wdd)) { in sp805_wdt_probe()
290 wdt_enable(&wdt->wdd); in sp805_wdt_probe()
291 set_bit(WDOG_HW_RUNNING, &wdt->wdd.status); in sp805_wdt_probe()
294 ret = watchdog_register_device(&wdt->wdd); in sp805_wdt_probe()
297 amba_set_drvdata(adev, wdt); in sp805_wdt_probe()
309 struct sp805_wdt *wdt = amba_get_drvdata(adev); in sp805_wdt_remove() local
311 watchdog_unregister_device(&wdt->wdd); in sp805_wdt_remove()
312 watchdog_set_drvdata(&wdt->wdd, NULL); in sp805_wdt_remove()
319 struct sp805_wdt *wdt = dev_get_drvdata(dev); in sp805_wdt_suspend() local
321 if (watchdog_active(&wdt->wdd)) in sp805_wdt_suspend()
322 return wdt_disable(&wdt->wdd); in sp805_wdt_suspend()
329 struct sp805_wdt *wdt = dev_get_drvdata(dev); in sp805_wdt_resume() local
331 if (watchdog_active(&wdt->wdd)) in sp805_wdt_resume()
332 return wdt_enable(&wdt->wdd); in sp805_wdt_resume()