diff options
Diffstat (limited to 'drivers/char/watchdog/mpc8xx_wdt.c')
-rw-r--r-- | drivers/char/watchdog/mpc8xx_wdt.c | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/drivers/char/watchdog/mpc8xx_wdt.c b/drivers/char/watchdog/mpc8xx_wdt.c new file mode 100644 index 000000000000..56d62ba7c6ce --- /dev/null +++ b/drivers/char/watchdog/mpc8xx_wdt.c | |||
@@ -0,0 +1,164 @@ | |||
1 | /* | ||
2 | * mpc8xx_wdt.c - MPC8xx watchdog userspace interface | ||
3 | * | ||
4 | * Author: Florian Schirmer <jolt@tuxbox.org> | ||
5 | * | ||
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 | ||
9 | * or implied. | ||
10 | */ | ||
11 | |||
12 | #include <linux/config.h> | ||
13 | #include <linux/fs.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> | ||
22 | |||
23 | static unsigned long wdt_opened; | ||
24 | static int wdt_status; | ||
25 | |||
26 | static void mpc8xx_wdt_handler_disable(void) | ||
27 | { | ||
28 | volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR; | ||
29 | |||
30 | imap->im_sit.sit_piscr &= ~(PISCR_PIE | PISCR_PTE); | ||
31 | |||
32 | printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler deactivated\n"); | ||
33 | } | ||
34 | |||
35 | static void mpc8xx_wdt_handler_enable(void) | ||
36 | { | ||
37 | volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR; | ||
38 | |||
39 | imap->im_sit.sit_piscr |= PISCR_PIE | PISCR_PTE; | ||
40 | |||
41 | printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler activated\n"); | ||
42 | } | ||
43 | |||
44 | static int mpc8xx_wdt_open(struct inode *inode, struct file *file) | ||
45 | { | ||
46 | if (test_and_set_bit(0, &wdt_opened)) | ||
47 | return -EBUSY; | ||
48 | |||
49 | m8xx_wdt_reset(); | ||
50 | mpc8xx_wdt_handler_disable(); | ||
51 | |||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | static int mpc8xx_wdt_release(struct inode *inode, struct file *file) | ||
56 | { | ||
57 | m8xx_wdt_reset(); | ||
58 | |||
59 | #if !defined(CONFIG_WATCHDOG_NOWAYOUT) | ||
60 | mpc8xx_wdt_handler_enable(); | ||
61 | #endif | ||
62 | |||
63 | clear_bit(0, &wdt_opened); | ||
64 | |||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | static ssize_t mpc8xx_wdt_write(struct file *file, const char *data, size_t len, | ||
69 | loff_t * ppos) | ||
70 | { | ||
71 | if (ppos != &file->f_pos) | ||
72 | return -ESPIPE; | ||
73 | |||
74 | if (len) | ||
75 | m8xx_wdt_reset(); | ||
76 | |||
77 | return len; | ||
78 | } | ||
79 | |||
80 | static int mpc8xx_wdt_ioctl(struct inode *inode, struct file *file, | ||
81 | unsigned int cmd, unsigned long arg) | ||
82 | { | ||
83 | int timeout; | ||
84 | static struct watchdog_info info = { | ||
85 | .options = WDIOF_KEEPALIVEPING, | ||
86 | .firmware_version = 0, | ||
87 | .identity = "MPC8xx watchdog", | ||
88 | }; | ||
89 | |||
90 | switch (cmd) { | ||
91 | case WDIOC_GETSUPPORT: | ||
92 | if (copy_to_user((void *)arg, &info, sizeof(info))) | ||
93 | return -EFAULT; | ||
94 | break; | ||
95 | |||
96 | case WDIOC_GETSTATUS: | ||
97 | case WDIOC_GETBOOTSTATUS: | ||
98 | if (put_user(wdt_status, (int *)arg)) | ||
99 | return -EFAULT; | ||
100 | wdt_status &= ~WDIOF_KEEPALIVEPING; | ||
101 | break; | ||
102 | |||
103 | case WDIOC_GETTEMP: | ||
104 | return -EOPNOTSUPP; | ||
105 | |||
106 | case WDIOC_SETOPTIONS: | ||
107 | return -EOPNOTSUPP; | ||
108 | |||
109 | case WDIOC_KEEPALIVE: | ||
110 | m8xx_wdt_reset(); | ||
111 | wdt_status |= WDIOF_KEEPALIVEPING; | ||
112 | break; | ||
113 | |||
114 | case WDIOC_SETTIMEOUT: | ||
115 | return -EOPNOTSUPP; | ||
116 | |||
117 | case WDIOC_GETTIMEOUT: | ||
118 | timeout = m8xx_wdt_get_timeout(); | ||
119 | if (put_user(timeout, (int *)arg)) | ||
120 | return -EFAULT; | ||
121 | break; | ||
122 | |||
123 | default: | ||
124 | return -ENOIOCTLCMD; | ||
125 | } | ||
126 | |||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | static struct file_operations mpc8xx_wdt_fops = { | ||
131 | .owner = THIS_MODULE, | ||
132 | .llseek = no_llseek, | ||
133 | .write = mpc8xx_wdt_write, | ||
134 | .ioctl = mpc8xx_wdt_ioctl, | ||
135 | .open = mpc8xx_wdt_open, | ||
136 | .release = mpc8xx_wdt_release, | ||
137 | }; | ||
138 | |||
139 | static struct miscdevice mpc8xx_wdt_miscdev = { | ||
140 | .minor = WATCHDOG_MINOR, | ||
141 | .name = "watchdog", | ||
142 | .fops = &mpc8xx_wdt_fops, | ||
143 | }; | ||
144 | |||
145 | static int __init mpc8xx_wdt_init(void) | ||
146 | { | ||
147 | return misc_register(&mpc8xx_wdt_miscdev); | ||
148 | } | ||
149 | |||
150 | static void __exit mpc8xx_wdt_exit(void) | ||
151 | { | ||
152 | misc_deregister(&mpc8xx_wdt_miscdev); | ||
153 | |||
154 | m8xx_wdt_reset(); | ||
155 | mpc8xx_wdt_handler_enable(); | ||
156 | } | ||
157 | |||
158 | module_init(mpc8xx_wdt_init); | ||
159 | module_exit(mpc8xx_wdt_exit); | ||
160 | |||
161 | MODULE_AUTHOR("Florian Schirmer <jolt@tuxbox.org>"); | ||
162 | MODULE_DESCRIPTION("MPC8xx watchdog driver"); | ||
163 | MODULE_LICENSE("GPL"); | ||
164 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); | ||