2727#include <linux/moduleparam.h>
2828#include <linux/types.h>
2929#include <linux/timer.h>
30- #include <linux/miscdevice.h>
30+ #include <linux/miscdevice.h> /* for MODULE_ALIAS_MISCDEV */
3131#include <linux/watchdog.h>
32- #include <linux/fs.h>
3332#include <linux/init.h>
3433#include <linux/platform_device.h>
3534#include <linux/interrupt.h>
3837#include <linux/io.h>
3938#include <linux/cpufreq.h>
4039#include <linux/slab.h>
40+ #include <linux/err.h>
4141
4242#include <mach/map.h>
4343
@@ -74,14 +74,12 @@ MODULE_PARM_DESC(soft_noboot, "Watchdog action, set to 1 to ignore reboots, "
7474 "0 to reboot (default 0)" );
7575MODULE_PARM_DESC (debug , "Watchdog debug, set to >1 for debug (default 0)" );
7676
77- static unsigned long open_lock ;
7877static struct device * wdt_dev ; /* platform device attached to */
7978static struct resource * wdt_mem ;
8079static struct resource * wdt_irq ;
8180static struct clk * wdt_clock ;
8281static void __iomem * wdt_base ;
8382static unsigned int wdt_count ;
84- static char expect_close ;
8583static DEFINE_SPINLOCK (wdt_lock );
8684
8785/* watchdog control routines */
@@ -93,11 +91,13 @@ static DEFINE_SPINLOCK(wdt_lock);
9391
9492/* functions */
9593
96- static void s3c2410wdt_keepalive (void )
94+ static int s3c2410wdt_keepalive (struct watchdog_device * wdd )
9795{
9896 spin_lock (& wdt_lock );
9997 writel (wdt_count , wdt_base + S3C2410_WTCNT );
10098 spin_unlock (& wdt_lock );
99+
100+ return 0 ;
101101}
102102
103103static void __s3c2410wdt_stop (void )
@@ -109,14 +109,16 @@ static void __s3c2410wdt_stop(void)
109109 writel (wtcon , wdt_base + S3C2410_WTCON );
110110}
111111
112- static void s3c2410wdt_stop (void )
112+ static int s3c2410wdt_stop (struct watchdog_device * wdd )
113113{
114114 spin_lock (& wdt_lock );
115115 __s3c2410wdt_stop ();
116116 spin_unlock (& wdt_lock );
117+
118+ return 0 ;
117119}
118120
119- static void s3c2410wdt_start (void )
121+ static int s3c2410wdt_start (struct watchdog_device * wdd )
120122{
121123 unsigned long wtcon ;
122124
@@ -142,14 +144,16 @@ static void s3c2410wdt_start(void)
142144 writel (wdt_count , wdt_base + S3C2410_WTCNT );
143145 writel (wtcon , wdt_base + S3C2410_WTCON );
144146 spin_unlock (& wdt_lock );
147+
148+ return 0 ;
145149}
146150
147151static inline int s3c2410wdt_is_running (void )
148152{
149153 return readl (wdt_base + S3C2410_WTCON ) & S3C2410_WTCON_ENABLE ;
150154}
151155
152- static int s3c2410wdt_set_heartbeat (int timeout )
156+ static int s3c2410wdt_set_heartbeat (struct watchdog_device * wdd , unsigned timeout )
153157{
154158 unsigned long freq = clk_get_rate (wdt_clock );
155159 unsigned int count ;
@@ -182,8 +186,6 @@ static int s3c2410wdt_set_heartbeat(int timeout)
182186 }
183187 }
184188
185- tmr_margin = timeout ;
186-
187189 DBG ("%s: timeout=%d, divisor=%d, count=%d (%08x)\n" ,
188190 __func__ , timeout , divisor , count , count /divisor );
189191
@@ -201,70 +203,6 @@ static int s3c2410wdt_set_heartbeat(int timeout)
201203 return 0 ;
202204}
203205
204- /*
205- * /dev/watchdog handling
206- */
207-
208- static int s3c2410wdt_open (struct inode * inode , struct file * file )
209- {
210- if (test_and_set_bit (0 , & open_lock ))
211- return - EBUSY ;
212-
213- if (nowayout )
214- __module_get (THIS_MODULE );
215-
216- expect_close = 0 ;
217-
218- /* start the timer */
219- s3c2410wdt_start ();
220- return nonseekable_open (inode , file );
221- }
222-
223- static int s3c2410wdt_release (struct inode * inode , struct file * file )
224- {
225- /*
226- * Shut off the timer.
227- * Lock it in if it's a module and we set nowayout
228- */
229-
230- if (expect_close == 42 )
231- s3c2410wdt_stop ();
232- else {
233- dev_err (wdt_dev , "Unexpected close, not stopping watchdog\n" );
234- s3c2410wdt_keepalive ();
235- }
236- expect_close = 0 ;
237- clear_bit (0 , & open_lock );
238- return 0 ;
239- }
240-
241- static ssize_t s3c2410wdt_write (struct file * file , const char __user * data ,
242- size_t len , loff_t * ppos )
243- {
244- /*
245- * Refresh the timer.
246- */
247- if (len ) {
248- if (!nowayout ) {
249- size_t i ;
250-
251- /* In case it was set long ago */
252- expect_close = 0 ;
253-
254- for (i = 0 ; i != len ; i ++ ) {
255- char c ;
256-
257- if (get_user (c , data + i ))
258- return - EFAULT ;
259- if (c == 'V' )
260- expect_close = 42 ;
261- }
262- }
263- s3c2410wdt_keepalive ();
264- }
265- return len ;
266- }
267-
268206#define OPTIONS (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE)
269207
270208static const struct watchdog_info s3c2410_wdt_ident = {
@@ -273,53 +211,17 @@ static const struct watchdog_info s3c2410_wdt_ident = {
273211 .identity = "S3C2410 Watchdog" ,
274212};
275213
276-
277- static long s3c2410wdt_ioctl (struct file * file , unsigned int cmd ,
278- unsigned long arg )
279- {
280- void __user * argp = (void __user * )arg ;
281- int __user * p = argp ;
282- int new_margin ;
283-
284- switch (cmd ) {
285- case WDIOC_GETSUPPORT :
286- return copy_to_user (argp , & s3c2410_wdt_ident ,
287- sizeof (s3c2410_wdt_ident )) ? - EFAULT : 0 ;
288- case WDIOC_GETSTATUS :
289- case WDIOC_GETBOOTSTATUS :
290- return put_user (0 , p );
291- case WDIOC_KEEPALIVE :
292- s3c2410wdt_keepalive ();
293- return 0 ;
294- case WDIOC_SETTIMEOUT :
295- if (get_user (new_margin , p ))
296- return - EFAULT ;
297- if (s3c2410wdt_set_heartbeat (new_margin ))
298- return - EINVAL ;
299- s3c2410wdt_keepalive ();
300- return put_user (tmr_margin , p );
301- case WDIOC_GETTIMEOUT :
302- return put_user (tmr_margin , p );
303- default :
304- return - ENOTTY ;
305- }
306- }
307-
308- /* kernel interface */
309-
310- static const struct file_operations s3c2410wdt_fops = {
311- .owner = THIS_MODULE ,
312- .llseek = no_llseek ,
313- .write = s3c2410wdt_write ,
314- .unlocked_ioctl = s3c2410wdt_ioctl ,
315- .open = s3c2410wdt_open ,
316- .release = s3c2410wdt_release ,
214+ static struct watchdog_ops s3c2410wdt_ops = {
215+ .owner = THIS_MODULE ,
216+ .start = s3c2410wdt_start ,
217+ .stop = s3c2410wdt_stop ,
218+ .ping = s3c2410wdt_keepalive ,
219+ .set_timeout = s3c2410wdt_set_heartbeat ,
317220};
318221
319- static struct miscdevice s3c2410wdt_miscdev = {
320- .minor = WATCHDOG_MINOR ,
321- .name = "watchdog" ,
322- .fops = & s3c2410wdt_fops ,
222+ static struct watchdog_device s3c2410_wdd = {
223+ .info = & s3c2410_wdt_ident ,
224+ .ops = & s3c2410wdt_ops ,
323225};
324226
325227/* interrupt handler code */
@@ -328,7 +230,7 @@ static irqreturn_t s3c2410wdt_irq(int irqno, void *param)
328230{
329231 dev_info (wdt_dev , "watchdog timer expired (irq)\n" );
330232
331- s3c2410wdt_keepalive ();
233+ s3c2410wdt_keepalive (& s3c2410_wdd );
332234 return IRQ_HANDLED ;
333235}
334236
@@ -349,14 +251,14 @@ static int s3c2410wdt_cpufreq_transition(struct notifier_block *nb,
349251 * the watchdog is running.
350252 */
351253
352- s3c2410wdt_keepalive ();
254+ s3c2410wdt_keepalive (& s3c2410_wdd );
353255 } else if (val == CPUFREQ_POSTCHANGE ) {
354- s3c2410wdt_stop ();
256+ s3c2410wdt_stop (& s3c2410_wdd );
355257
356- ret = s3c2410wdt_set_heartbeat (tmr_margin );
258+ ret = s3c2410wdt_set_heartbeat (& s3c2410_wdd , s3c2410_wdd . timeout );
357259
358260 if (ret >= 0 )
359- s3c2410wdt_start ();
261+ s3c2410wdt_start (& s3c2410_wdd );
360262 else
361263 goto err ;
362264 }
@@ -365,7 +267,8 @@ static int s3c2410wdt_cpufreq_transition(struct notifier_block *nb,
365267 return 0 ;
366268
367269 err :
368- dev_err (wdt_dev , "cannot set new value for timeout %d\n" , tmr_margin );
270+ dev_err (wdt_dev , "cannot set new value for timeout %d\n" ,
271+ s3c2410_wdd .timeout );
369272 return ret ;
370273}
371274
@@ -396,10 +299,6 @@ static inline void s3c2410wdt_cpufreq_deregister(void)
396299}
397300#endif
398301
399-
400-
401- /* device interface */
402-
403302static int __devinit s3c2410wdt_probe (struct platform_device * pdev )
404303{
405304 struct device * dev ;
@@ -466,8 +365,8 @@ static int __devinit s3c2410wdt_probe(struct platform_device *pdev)
466365 /* see if we can actually set the requested timer margin, and if
467366 * not, try the default value */
468367
469- if (s3c2410wdt_set_heartbeat (tmr_margin )) {
470- started = s3c2410wdt_set_heartbeat (
368+ if (s3c2410wdt_set_heartbeat (& s3c2410_wdd , tmr_margin )) {
369+ started = s3c2410wdt_set_heartbeat (& s3c2410_wdd ,
471370 CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME );
472371
473372 if (started == 0 )
@@ -479,22 +378,21 @@ static int __devinit s3c2410wdt_probe(struct platform_device *pdev)
479378 "cannot start\n" );
480379 }
481380
482- ret = misc_register ( & s3c2410wdt_miscdev );
381+ ret = watchdog_register_device ( & s3c2410_wdd );
483382 if (ret ) {
484- dev_err (dev , "cannot register miscdev on minor=%d (%d)\n" ,
485- WATCHDOG_MINOR , ret );
383+ dev_err (dev , "cannot register watchdog (%d)\n" , ret );
486384 goto err_cpufreq ;
487385 }
488386
489387 if (tmr_atboot && started == 0 ) {
490388 dev_info (dev , "starting watchdog timer\n" );
491- s3c2410wdt_start ();
389+ s3c2410wdt_start (& s3c2410_wdd );
492390 } else if (!tmr_atboot ) {
493391 /* if we're not enabling the watchdog, then ensure it is
494392 * disabled if it has been left running from the bootloader
495393 * or other source */
496394
497- s3c2410wdt_stop ();
395+ s3c2410wdt_stop (& s3c2410_wdd );
498396 }
499397
500398 /* print out a statement of readiness */
@@ -530,7 +428,7 @@ static int __devinit s3c2410wdt_probe(struct platform_device *pdev)
530428
531429static int __devexit s3c2410wdt_remove (struct platform_device * dev )
532430{
533- misc_deregister ( & s3c2410wdt_miscdev );
431+ watchdog_unregister_device ( & s3c2410_wdd );
534432
535433 s3c2410wdt_cpufreq_deregister ();
536434
@@ -550,7 +448,7 @@ static int __devexit s3c2410wdt_remove(struct platform_device *dev)
550448
551449static void s3c2410wdt_shutdown (struct platform_device * dev )
552450{
553- s3c2410wdt_stop ();
451+ s3c2410wdt_stop (& s3c2410_wdd );
554452}
555453
556454#ifdef CONFIG_PM
@@ -565,7 +463,7 @@ static int s3c2410wdt_suspend(struct platform_device *dev, pm_message_t state)
565463 wtdat_save = readl (wdt_base + S3C2410_WTDAT );
566464
567465 /* Note that WTCNT doesn't need to be saved. */
568- s3c2410wdt_stop ();
466+ s3c2410wdt_stop (& s3c2410_wdd );
569467
570468 return 0 ;
571469}
0 commit comments