16 #include <linux/module.h>
18 #include <linux/types.h>
19 #include <linux/kernel.h>
21 #include <linux/watchdog.h>
25 #include <linux/device.h>
27 #include <linux/slab.h>
32 #define JZ_REG_WDT_TIMER_DATA 0x0
33 #define JZ_REG_WDT_COUNTER_ENABLE 0x4
34 #define JZ_REG_WDT_TIMER_COUNTER 0x8
35 #define JZ_REG_WDT_TIMER_CONTROL 0xC
37 #define JZ_WDT_CLOCK_PCLK 0x1
38 #define JZ_WDT_CLOCK_RTC 0x2
39 #define JZ_WDT_CLOCK_EXT 0x4
41 #define JZ_WDT_CLOCK_DIV_SHIFT 3
43 #define JZ_WDT_CLOCK_DIV_1 (0 << JZ_WDT_CLOCK_DIV_SHIFT)
44 #define JZ_WDT_CLOCK_DIV_4 (1 << JZ_WDT_CLOCK_DIV_SHIFT)
45 #define JZ_WDT_CLOCK_DIV_16 (2 << JZ_WDT_CLOCK_DIV_SHIFT)
46 #define JZ_WDT_CLOCK_DIV_64 (3 << JZ_WDT_CLOCK_DIV_SHIFT)
47 #define JZ_WDT_CLOCK_DIV_256 (4 << JZ_WDT_CLOCK_DIV_SHIFT)
48 #define JZ_WDT_CLOCK_DIV_1024 (5 << JZ_WDT_CLOCK_DIV_SHIFT)
50 #define DEFAULT_HEARTBEAT 5
51 #define MAX_HEARTBEAT 2048
56 "Watchdog cannot be stopped once started (default="
62 "Watchdog heartbeat period in seconds from 1 to "
81 unsigned int new_timeout)
84 unsigned int rtc_clk_rate;
85 unsigned int timeout_value;
90 timeout_value = rtc_clk_rate * new_timeout;
91 while (timeout_value > 0xffff) {
95 timeout_value = 0xffff;
112 wdt_dev->
timeout = new_timeout;
119 jz4740_wdt_set_timeout(wdt_dev, wdt_dev->
timeout);
136 .identity =
"jz4740 Watchdog",
141 .start = jz4740_wdt_start,
142 .stop = jz4740_wdt_stop,
143 .ping = jz4740_wdt_ping,
144 .set_timeout = jz4740_wdt_set_timeout,
157 dev_err(&pdev->
dev,
"Unable to alloacate watchdog device\n");
164 jz4740_wdt = &drvdata->
wdt;
165 jz4740_wdt->
info = &jz4740_wdt_info;
166 jz4740_wdt->
ops = &jz4740_wdt_ops;
170 watchdog_set_nowayout(jz4740_wdt, nowayout);
171 watchdog_set_drvdata(jz4740_wdt, drvdata);
181 if (IS_ERR(drvdata->
rtc_clk)) {
182 dev_err(&pdev->
dev,
"cannot find RTC clock\n");
183 ret = PTR_ERR(drvdata->
rtc_clk);
189 goto err_disable_clk;
191 platform_set_drvdata(pdev, drvdata);
204 jz4740_wdt_stop(&drvdata->
wdt);
212 .probe = jz4740_wdt_probe,
215 .name =
"jz4740-wdt",