diff options
Diffstat (limited to 'drivers/watchdog/acquirewdt.c')
-rw-r--r-- | drivers/watchdog/acquirewdt.c | 130 |
1 files changed, 63 insertions, 67 deletions
diff --git a/drivers/watchdog/acquirewdt.c b/drivers/watchdog/acquirewdt.c index 85269c365a10..6e46a551395c 100644 --- a/drivers/watchdog/acquirewdt.c +++ b/drivers/watchdog/acquirewdt.c | |||
@@ -58,39 +58,45 @@ | |||
58 | #include <linux/types.h> /* For standard types (like size_t) */ | 58 | #include <linux/types.h> /* For standard types (like size_t) */ |
59 | #include <linux/errno.h> /* For the -ENODEV/... values */ | 59 | #include <linux/errno.h> /* For the -ENODEV/... values */ |
60 | #include <linux/kernel.h> /* For printk/panic/... */ | 60 | #include <linux/kernel.h> /* For printk/panic/... */ |
61 | #include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */ | 61 | #include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV |
62 | (WATCHDOG_MINOR) */ | ||
62 | #include <linux/watchdog.h> /* For the watchdog specific items */ | 63 | #include <linux/watchdog.h> /* For the watchdog specific items */ |
63 | #include <linux/fs.h> /* For file operations */ | 64 | #include <linux/fs.h> /* For file operations */ |
64 | #include <linux/ioport.h> /* For io-port access */ | 65 | #include <linux/ioport.h> /* For io-port access */ |
65 | #include <linux/platform_device.h> /* For platform_driver framework */ | 66 | #include <linux/platform_device.h> /* For platform_driver framework */ |
66 | #include <linux/init.h> /* For __init/__exit/... */ | 67 | #include <linux/init.h> /* For __init/__exit/... */ |
67 | 68 | #include <linux/uaccess.h> /* For copy_to_user/put_user/... */ | |
68 | #include <asm/uaccess.h> /* For copy_to_user/put_user/... */ | 69 | #include <linux/io.h> /* For inb/outb/... */ |
69 | #include <asm/io.h> /* For inb/outb/... */ | ||
70 | 70 | ||
71 | /* Module information */ | 71 | /* Module information */ |
72 | #define DRV_NAME "acquirewdt" | 72 | #define DRV_NAME "acquirewdt" |
73 | #define PFX DRV_NAME ": " | 73 | #define PFX DRV_NAME ": " |
74 | #define WATCHDOG_NAME "Acquire WDT" | 74 | #define WATCHDOG_NAME "Acquire WDT" |
75 | #define WATCHDOG_HEARTBEAT 0 /* There is no way to see what the correct time-out period is */ | 75 | /* There is no way to see what the correct time-out period is */ |
76 | #define WATCHDOG_HEARTBEAT 0 | ||
76 | 77 | ||
77 | /* internal variables */ | 78 | /* internal variables */ |
78 | static struct platform_device *acq_platform_device; /* the watchdog platform device */ | 79 | /* the watchdog platform device */ |
80 | static struct platform_device *acq_platform_device; | ||
79 | static unsigned long acq_is_open; | 81 | static unsigned long acq_is_open; |
80 | static char expect_close; | 82 | static char expect_close; |
81 | 83 | ||
82 | /* module parameters */ | 84 | /* module parameters */ |
83 | static int wdt_stop = 0x43; /* You must set this - there is no sane way to probe for this board. */ | 85 | /* You must set this - there is no sane way to probe for this board. */ |
86 | static int wdt_stop = 0x43; | ||
84 | module_param(wdt_stop, int, 0); | 87 | module_param(wdt_stop, int, 0); |
85 | MODULE_PARM_DESC(wdt_stop, "Acquire WDT 'stop' io port (default 0x43)"); | 88 | MODULE_PARM_DESC(wdt_stop, "Acquire WDT 'stop' io port (default 0x43)"); |
86 | 89 | ||
87 | static int wdt_start = 0x443; /* You must set this - there is no sane way to probe for this board. */ | 90 | /* You must set this - there is no sane way to probe for this board. */ |
91 | static int wdt_start = 0x443; | ||
88 | module_param(wdt_start, int, 0); | 92 | module_param(wdt_start, int, 0); |
89 | MODULE_PARM_DESC(wdt_start, "Acquire WDT 'start' io port (default 0x443)"); | 93 | MODULE_PARM_DESC(wdt_start, "Acquire WDT 'start' io port (default 0x443)"); |
90 | 94 | ||
91 | static int nowayout = WATCHDOG_NOWAYOUT; | 95 | static int nowayout = WATCHDOG_NOWAYOUT; |
92 | module_param(nowayout, int, 0); | 96 | module_param(nowayout, int, 0); |
93 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | 97 | MODULE_PARM_DESC(nowayout, |
98 | "Watchdog cannot be stopped once started (default=" | ||
99 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | ||
94 | 100 | ||
95 | /* | 101 | /* |
96 | * Watchdog Operations | 102 | * Watchdog Operations |
@@ -112,18 +118,18 @@ static void acq_stop(void) | |||
112 | * /dev/watchdog handling | 118 | * /dev/watchdog handling |
113 | */ | 119 | */ |
114 | 120 | ||
115 | static ssize_t acq_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) | 121 | static ssize_t acq_write(struct file *file, const char __user *buf, |
122 | size_t count, loff_t *ppos) | ||
116 | { | 123 | { |
117 | /* See if we got the magic character 'V' and reload the timer */ | 124 | /* See if we got the magic character 'V' and reload the timer */ |
118 | if(count) { | 125 | if (count) { |
119 | if (!nowayout) { | 126 | if (!nowayout) { |
120 | size_t i; | 127 | size_t i; |
121 | |||
122 | /* note: just in case someone wrote the magic character | 128 | /* note: just in case someone wrote the magic character |
123 | * five months ago... */ | 129 | five months ago... */ |
124 | expect_close = 0; | 130 | expect_close = 0; |
125 | 131 | /* scan to see whether or not we got the | |
126 | /* scan to see whether or not we got the magic character */ | 132 | magic character */ |
127 | for (i = 0; i != count; i++) { | 133 | for (i = 0; i != count; i++) { |
128 | char c; | 134 | char c; |
129 | if (get_user(c, buf + i)) | 135 | if (get_user(c, buf + i)) |
@@ -132,64 +138,55 @@ static ssize_t acq_write(struct file *file, const char __user *buf, size_t count | |||
132 | expect_close = 42; | 138 | expect_close = 42; |
133 | } | 139 | } |
134 | } | 140 | } |
135 | 141 | /* Well, anyhow someone wrote to us, we should | |
136 | /* Well, anyhow someone wrote to us, we should return that favour */ | 142 | return that favour */ |
137 | acq_keepalive(); | 143 | acq_keepalive(); |
138 | } | 144 | } |
139 | return count; | 145 | return count; |
140 | } | 146 | } |
141 | 147 | ||
142 | static int acq_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | 148 | static long acq_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
143 | unsigned long arg) | ||
144 | { | 149 | { |
145 | int options, retval = -EINVAL; | 150 | int options, retval = -EINVAL; |
146 | void __user *argp = (void __user *)arg; | 151 | void __user *argp = (void __user *)arg; |
147 | int __user *p = argp; | 152 | int __user *p = argp; |
148 | static struct watchdog_info ident = | 153 | static struct watchdog_info ident = { |
149 | { | ||
150 | .options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, | 154 | .options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, |
151 | .firmware_version = 1, | 155 | .firmware_version = 1, |
152 | .identity = WATCHDOG_NAME, | 156 | .identity = WATCHDOG_NAME, |
153 | }; | 157 | }; |
154 | 158 | ||
155 | switch(cmd) | 159 | switch (cmd) { |
156 | { | ||
157 | case WDIOC_GETSUPPORT: | 160 | case WDIOC_GETSUPPORT: |
158 | return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; | 161 | return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; |
159 | 162 | ||
160 | case WDIOC_GETSTATUS: | 163 | case WDIOC_GETSTATUS: |
161 | case WDIOC_GETBOOTSTATUS: | 164 | case WDIOC_GETBOOTSTATUS: |
162 | return put_user(0, p); | 165 | return put_user(0, p); |
163 | |||
164 | case WDIOC_KEEPALIVE: | ||
165 | acq_keepalive(); | ||
166 | return 0; | ||
167 | |||
168 | case WDIOC_GETTIMEOUT: | ||
169 | return put_user(WATCHDOG_HEARTBEAT, p); | ||
170 | 166 | ||
171 | case WDIOC_SETOPTIONS: | 167 | case WDIOC_SETOPTIONS: |
172 | { | 168 | { |
173 | if (get_user(options, p)) | 169 | if (get_user(options, p)) |
174 | return -EFAULT; | 170 | return -EFAULT; |
175 | 171 | if (options & WDIOS_DISABLECARD) { | |
176 | if (options & WDIOS_DISABLECARD) | 172 | acq_stop(); |
177 | { | 173 | retval = 0; |
178 | acq_stop(); | 174 | } |
179 | retval = 0; | 175 | if (options & WDIOS_ENABLECARD) { |
180 | } | 176 | acq_keepalive(); |
181 | 177 | retval = 0; | |
182 | if (options & WDIOS_ENABLECARD) | 178 | } |
183 | { | 179 | return retval; |
184 | acq_keepalive(); | ||
185 | retval = 0; | ||
186 | } | ||
187 | |||
188 | return retval; | ||
189 | } | 180 | } |
181 | case WDIOC_KEEPALIVE: | ||
182 | acq_keepalive(); | ||
183 | return 0; | ||
184 | |||
185 | case WDIOC_GETTIMEOUT: | ||
186 | return put_user(WATCHDOG_HEARTBEAT, p); | ||
190 | 187 | ||
191 | default: | 188 | default: |
192 | return -ENOTTY; | 189 | return -ENOTTY; |
193 | } | 190 | } |
194 | } | 191 | } |
195 | 192 | ||
@@ -211,7 +208,8 @@ static int acq_close(struct inode *inode, struct file *file) | |||
211 | if (expect_close == 42) { | 208 | if (expect_close == 42) { |
212 | acq_stop(); | 209 | acq_stop(); |
213 | } else { | 210 | } else { |
214 | printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); | 211 | printk(KERN_CRIT PFX |
212 | "Unexpected close, not stopping watchdog!\n"); | ||
215 | acq_keepalive(); | 213 | acq_keepalive(); |
216 | } | 214 | } |
217 | clear_bit(0, &acq_is_open); | 215 | clear_bit(0, &acq_is_open); |
@@ -227,7 +225,7 @@ static const struct file_operations acq_fops = { | |||
227 | .owner = THIS_MODULE, | 225 | .owner = THIS_MODULE, |
228 | .llseek = no_llseek, | 226 | .llseek = no_llseek, |
229 | .write = acq_write, | 227 | .write = acq_write, |
230 | .ioctl = acq_ioctl, | 228 | .unlocked_ioctl = acq_ioctl, |
231 | .open = acq_open, | 229 | .open = acq_open, |
232 | .release = acq_close, | 230 | .release = acq_close, |
233 | }; | 231 | }; |
@@ -248,32 +246,29 @@ static int __devinit acq_probe(struct platform_device *dev) | |||
248 | 246 | ||
249 | if (wdt_stop != wdt_start) { | 247 | if (wdt_stop != wdt_start) { |
250 | if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) { | 248 | if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) { |
251 | printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", | 249 | printk(KERN_ERR PFX |
252 | wdt_stop); | 250 | "I/O address 0x%04x already in use\n", wdt_stop); |
253 | ret = -EIO; | 251 | ret = -EIO; |
254 | goto out; | 252 | goto out; |
255 | } | 253 | } |
256 | } | 254 | } |
257 | 255 | ||
258 | if (!request_region(wdt_start, 1, WATCHDOG_NAME)) { | 256 | if (!request_region(wdt_start, 1, WATCHDOG_NAME)) { |
259 | printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", | 257 | printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", |
260 | wdt_start); | 258 | wdt_start); |
261 | ret = -EIO; | 259 | ret = -EIO; |
262 | goto unreg_stop; | 260 | goto unreg_stop; |
263 | } | 261 | } |
264 | |||
265 | ret = misc_register(&acq_miscdev); | 262 | ret = misc_register(&acq_miscdev); |
266 | if (ret != 0) { | 263 | if (ret != 0) { |
267 | printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", | 264 | printk(KERN_ERR PFX |
268 | WATCHDOG_MINOR, ret); | 265 | "cannot register miscdev on minor=%d (err=%d)\n", |
266 | WATCHDOG_MINOR, ret); | ||
269 | goto unreg_regions; | 267 | goto unreg_regions; |
270 | } | 268 | } |
271 | 269 | printk(KERN_INFO PFX "initialized. (nowayout=%d)\n", nowayout); | |
272 | printk (KERN_INFO PFX "initialized. (nowayout=%d)\n", | ||
273 | nowayout); | ||
274 | 270 | ||
275 | return 0; | 271 | return 0; |
276 | |||
277 | unreg_regions: | 272 | unreg_regions: |
278 | release_region(wdt_start, 1); | 273 | release_region(wdt_start, 1); |
279 | unreg_stop: | 274 | unreg_stop: |
@@ -286,9 +281,9 @@ out: | |||
286 | static int __devexit acq_remove(struct platform_device *dev) | 281 | static int __devexit acq_remove(struct platform_device *dev) |
287 | { | 282 | { |
288 | misc_deregister(&acq_miscdev); | 283 | misc_deregister(&acq_miscdev); |
289 | release_region(wdt_start,1); | 284 | release_region(wdt_start, 1); |
290 | if(wdt_stop != wdt_start) | 285 | if (wdt_stop != wdt_start) |
291 | release_region(wdt_stop,1); | 286 | release_region(wdt_stop, 1); |
292 | 287 | ||
293 | return 0; | 288 | return 0; |
294 | } | 289 | } |
@@ -313,18 +308,19 @@ static int __init acq_init(void) | |||
313 | { | 308 | { |
314 | int err; | 309 | int err; |
315 | 310 | ||
316 | printk(KERN_INFO "WDT driver for Acquire single board computer initialising.\n"); | 311 | printk(KERN_INFO |
312 | "WDT driver for Acquire single board computer initialising.\n"); | ||
317 | 313 | ||
318 | err = platform_driver_register(&acquirewdt_driver); | 314 | err = platform_driver_register(&acquirewdt_driver); |
319 | if (err) | 315 | if (err) |
320 | return err; | 316 | return err; |
321 | 317 | ||
322 | acq_platform_device = platform_device_register_simple(DRV_NAME, -1, NULL, 0); | 318 | acq_platform_device = platform_device_register_simple(DRV_NAME, |
319 | -1, NULL, 0); | ||
323 | if (IS_ERR(acq_platform_device)) { | 320 | if (IS_ERR(acq_platform_device)) { |
324 | err = PTR_ERR(acq_platform_device); | 321 | err = PTR_ERR(acq_platform_device); |
325 | goto unreg_platform_driver; | 322 | goto unreg_platform_driver; |
326 | } | 323 | } |
327 | |||
328 | return 0; | 324 | return 0; |
329 | 325 | ||
330 | unreg_platform_driver: | 326 | unreg_platform_driver: |