21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #include <linux/module.h>
27 #include <linux/types.h>
30 #include <linux/watchdog.h>
34 #include <linux/slab.h>
37 #include <asm/watchdog.h>
39 #define DRV_NAME "sh-wdt"
68 static int clock_division_ratio = WTCSR_CKS_4096;
69 #define next_ping_period(cks) (jiffies + msecs_to_jiffies(cks - 4))
71 #define WATCHDOG_HEARTBEAT 30
87 struct sh_wdt *wdt = watchdog_get_drvdata(wdt_dev);
91 pm_runtime_get_sync(wdt->
dev);
99 csr = sh_wdt_read_csr();
100 csr |=
WTCSR_WT | clock_division_ratio;
101 sh_wdt_write_csr(csr);
113 csr = sh_wdt_read_csr();
116 sh_wdt_write_csr(csr);
118 #ifdef CONFIG_CPU_SH2
119 csr = sh_wdt_read_rstcsr();
121 sh_wdt_write_rstcsr(csr);
123 spin_unlock_irqrestore(&wdt->
lock, flags);
130 struct sh_wdt *wdt = watchdog_get_drvdata(wdt_dev);
138 csr = sh_wdt_read_csr();
140 sh_wdt_write_csr(csr);
142 spin_unlock_irqrestore(&wdt->
lock, flags);
145 pm_runtime_put_sync(wdt->
dev);
152 struct sh_wdt *wdt = watchdog_get_drvdata(wdt_dev);
157 spin_unlock_irqrestore(&wdt->
lock, flags);
162 static int sh_wdt_set_heartbeat(
struct watchdog_device *wdt_dev,
unsigned t)
164 struct sh_wdt *wdt = watchdog_get_drvdata(wdt_dev);
173 spin_unlock_irqrestore(&wdt->
lock, flags);
178 static void sh_wdt_ping(
unsigned long data)
187 csr = sh_wdt_read_csr();
189 sh_wdt_write_csr(csr);
195 dev_warn(wdt->
dev,
"Heartbeat lost! Will not ping "
197 spin_unlock_irqrestore(&wdt->
lock, flags);
203 .firmware_version = 1,
204 .identity =
"SH WDT",
209 .start = sh_wdt_start,
211 .ping = sh_wdt_keepalive,
212 .set_timeout = sh_wdt_set_heartbeat,
216 .info = &sh_wdt_info,
244 if (IS_ERR(wdt->
clk)) {
258 watchdog_set_nowayout(&sh_wdt_dev, nowayout);
259 watchdog_set_drvdata(&sh_wdt_dev, wdt);
263 rc = sh_wdt_set_heartbeat(&sh_wdt_dev,
heartbeat);
269 "heartbeat value must be 1<=x<=3600, using %d\n",
273 dev_info(&pdev->
dev,
"configured with heartbeat=%d sec (nowayout=%d)\n",
278 dev_err(&pdev->
dev,
"Can't register watchdog (err=%d)\n", rc);
283 wdt->
timer.function = sh_wdt_ping;
287 platform_set_drvdata(pdev, wdt);
303 struct sh_wdt *wdt = platform_get_drvdata(pdev);
305 platform_set_drvdata(pdev,
NULL);
309 pm_runtime_disable(&pdev->
dev);
317 sh_wdt_stop(&sh_wdt_dev);
326 .probe = sh_wdt_probe,
328 .shutdown = sh_wdt_shutdown,
331 static int __init sh_wdt_init(
void)
333 if (
unlikely(clock_division_ratio < 0x5 ||
334 clock_division_ratio > 0x7)) {
335 clock_division_ratio = WTCSR_CKS_4096;
337 pr_info(
"divisor must be 0x5<=x<=0x7, using %d\n",
338 clock_division_ratio);
344 static void __exit sh_wdt_exit(
void)
359 "Clock division ratio. Valid ranges are from 0x5 (1.31ms) "
364 "Watchdog heartbeat in seconds. (1 <= heartbeat <= 3600, default="
369 "Watchdog cannot be stopped once started (default="