14 #include <linux/device.h>
15 #include <linux/resource.h>
17 #include <linux/bitops.h>
22 #include <linux/kernel.h>
24 #include <linux/module.h>
27 #include <linux/slab.h>
29 #include <linux/types.h>
30 #include <linux/watchdog.h>
33 #define DEFAULT_TIMEOUT 60
35 #define MODULE_NAME "sp805-wdt"
39 #define LOAD_MIN 0x00000001
40 #define LOAD_MAX 0xFFFFFFFF
41 #define WDTVALUE 0x004
42 #define WDTCONTROL 0x008
44 #define INT_ENABLE (1 << 0)
45 #define RESET_ENABLE (1 << 1)
46 #define WDTINTCLR 0x00C
49 #define INT_MASK (1 << 0)
51 #define UNLOCK 0x1ACCE551
52 #define LOCK 0x00000001
78 "Set to 1 to keep watchdog running after device release");
81 static int wdt_setload(
struct watchdog_device *wdd,
unsigned int timeout)
83 struct sp805_wdt *wdt = watchdog_get_drvdata(wdd);
94 load = div_u64(rate, 2) * timeout - 1;
99 spin_lock(&wdt->
lock);
102 wdt->
timeout = div_u64((load + 1) * 2 + (rate / 2), rate);
103 spin_unlock(&wdt->
lock);
111 struct sp805_wdt *wdt = watchdog_get_drvdata(wdd);
116 spin_lock(&wdt->
lock);
122 spin_unlock(&wdt->
lock);
124 return div_u64(load, rate);
129 struct sp805_wdt *wdt = watchdog_get_drvdata(wdd);
147 spin_lock(&wdt->
lock);
162 spin_unlock(&wdt->
lock);
169 return wdt_config(wdd,
true);
175 return wdt_config(wdd,
false);
181 struct sp805_wdt *wdt = watchdog_get_drvdata(wdd);
183 spin_lock(&wdt->
lock);
191 spin_unlock(&wdt->
lock);
209 .set_timeout = wdt_setload,
210 .get_timeleft = wdt_timeleft,
220 resource_size(&adev->
res),
"sp805_wdt")) {
221 dev_warn(&adev->
dev,
"Failed to get memory region resource\n");
234 resource_size(&adev->
res));
242 if (IS_ERR(wdt->
clk)) {
244 ret = PTR_ERR(wdt->
clk);
249 wdt->
wdd.info = &wdt_info;
250 wdt->
wdd.ops = &wdt_ops;
253 watchdog_set_nowayout(&wdt->
wdd, nowayout);
254 watchdog_set_drvdata(&wdt->
wdd, wdt);
259 dev_err(&adev->
dev,
"watchdog_register_device() failed: %d\n",
281 watchdog_set_drvdata(&wdt->
wdd,
NULL);
288 static int sp805_wdt_suspend(
struct device *
dev)
292 if (watchdog_active(&wdt->
wdd))
293 return wdt_disable(&wdt->
wdd);
298 static int sp805_wdt_resume(
struct device *dev)
302 if (watchdog_active(&wdt->
wdd))
303 return wdt_enable(&wdt->
wdd);
312 static struct amba_id sp805_wdt_ids[] = {
325 .pm = &sp805_wdt_dev_pm_ops,
327 .id_table = sp805_wdt_ids,
328 .probe = sp805_wdt_probe,