2 * mpc8xx_wdt.c - MPC8xx watchdog userspace interface
4 * Author: Florian Schirmer <jolt@tuxbox.org>
6 * 2002 (c) Florian Schirmer <jolt@tuxbox.org> This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
12 #include <linux/config.h>
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/miscdevice.h>
17 #include <linux/module.h>
18 #include <linux/watchdog.h>
19 #include <asm/8xx_immap.h>
20 #include <asm/uaccess.h>
21 #include <syslib/m8xx_wdt.h>
23 static unsigned long wdt_opened
;
24 static int wdt_status
;
26 static void mpc8xx_wdt_handler_disable(void)
28 volatile immap_t
*imap
= (volatile immap_t
*)IMAP_ADDR
;
30 imap
->im_sit
.sit_piscr
&= ~(PISCR_PIE
| PISCR_PTE
);
32 printk(KERN_NOTICE
"mpc8xx_wdt: keep-alive handler deactivated\n");
35 static void mpc8xx_wdt_handler_enable(void)
37 volatile immap_t
*imap
= (volatile immap_t
*)IMAP_ADDR
;
39 imap
->im_sit
.sit_piscr
|= PISCR_PIE
| PISCR_PTE
;
41 printk(KERN_NOTICE
"mpc8xx_wdt: keep-alive handler activated\n");
44 static int mpc8xx_wdt_open(struct inode
*inode
, struct file
*file
)
46 if (test_and_set_bit(0, &wdt_opened
))
50 mpc8xx_wdt_handler_disable();
55 static int mpc8xx_wdt_release(struct inode
*inode
, struct file
*file
)
59 #if !defined(CONFIG_WATCHDOG_NOWAYOUT)
60 mpc8xx_wdt_handler_enable();
63 clear_bit(0, &wdt_opened
);
68 static ssize_t
mpc8xx_wdt_write(struct file
*file
, const char *data
, size_t len
,
71 if (ppos
!= &file
->f_pos
)
80 static int mpc8xx_wdt_ioctl(struct inode
*inode
, struct file
*file
,
81 unsigned int cmd
, unsigned long arg
)
84 static struct watchdog_info info
= {
85 .options
= WDIOF_KEEPALIVEPING
,
86 .firmware_version
= 0,
87 .identity
= "MPC8xx watchdog",
91 case WDIOC_GETSUPPORT
:
92 if (copy_to_user((void *)arg
, &info
, sizeof(info
)))
97 case WDIOC_GETBOOTSTATUS
:
98 if (put_user(wdt_status
, (int *)arg
))
100 wdt_status
&= ~WDIOF_KEEPALIVEPING
;
106 case WDIOC_SETOPTIONS
:
109 case WDIOC_KEEPALIVE
:
111 wdt_status
|= WDIOF_KEEPALIVEPING
;
114 case WDIOC_SETTIMEOUT
:
117 case WDIOC_GETTIMEOUT
:
118 timeout
= m8xx_wdt_get_timeout();
119 if (put_user(timeout
, (int *)arg
))
130 static struct file_operations mpc8xx_wdt_fops
= {
131 .owner
= THIS_MODULE
,
133 .write
= mpc8xx_wdt_write
,
134 .ioctl
= mpc8xx_wdt_ioctl
,
135 .open
= mpc8xx_wdt_open
,
136 .release
= mpc8xx_wdt_release
,
139 static struct miscdevice mpc8xx_wdt_miscdev
= {
140 .minor
= WATCHDOG_MINOR
,
142 .fops
= &mpc8xx_wdt_fops
,
145 static int __init
mpc8xx_wdt_init(void)
147 return misc_register(&mpc8xx_wdt_miscdev
);
150 static void __exit
mpc8xx_wdt_exit(void)
152 misc_deregister(&mpc8xx_wdt_miscdev
);
155 mpc8xx_wdt_handler_enable();
158 module_init(mpc8xx_wdt_init
);
159 module_exit(mpc8xx_wdt_exit
);
161 MODULE_AUTHOR("Florian Schirmer <jolt@tuxbox.org>");
162 MODULE_DESCRIPTION("MPC8xx watchdog driver");
163 MODULE_LICENSE("GPL");
164 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR
);