diff options
Diffstat (limited to 'drivers/watchdog/alim1535_wdt.c')
-rw-r--r-- | drivers/watchdog/alim1535_wdt.c | 186 |
1 files changed, 91 insertions, 95 deletions
diff --git a/drivers/watchdog/alim1535_wdt.c b/drivers/watchdog/alim1535_wdt.c index 2b1fbdb2fcf7..88760cb5ec13 100644 --- a/drivers/watchdog/alim1535_wdt.c +++ b/drivers/watchdog/alim1535_wdt.c | |||
@@ -19,8 +19,8 @@ | |||
19 | #include <linux/fs.h> | 19 | #include <linux/fs.h> |
20 | #include <linux/pci.h> | 20 | #include <linux/pci.h> |
21 | 21 | ||
22 | #include <asm/uaccess.h> | 22 | #include <linux/uaccess.h> |
23 | #include <asm/io.h> | 23 | #include <linux/io.h> |
24 | 24 | ||
25 | #define WATCHDOG_NAME "ALi_M1535" | 25 | #define WATCHDOG_NAME "ALi_M1535" |
26 | #define PFX WATCHDOG_NAME ": " | 26 | #define PFX WATCHDOG_NAME ": " |
@@ -30,17 +30,21 @@ | |||
30 | static unsigned long ali_is_open; | 30 | static unsigned long ali_is_open; |
31 | static char ali_expect_release; | 31 | static char ali_expect_release; |
32 | static struct pci_dev *ali_pci; | 32 | static struct pci_dev *ali_pci; |
33 | static u32 ali_timeout_bits; /* stores the computed timeout */ | 33 | static u32 ali_timeout_bits; /* stores the computed timeout */ |
34 | static DEFINE_SPINLOCK(ali_lock); /* Guards the hardware */ | 34 | static DEFINE_SPINLOCK(ali_lock); /* Guards the hardware */ |
35 | 35 | ||
36 | /* module parameters */ | 36 | /* module parameters */ |
37 | static int timeout = WATCHDOG_TIMEOUT; | 37 | static int timeout = WATCHDOG_TIMEOUT; |
38 | module_param(timeout, int, 0); | 38 | module_param(timeout, int, 0); |
39 | MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (0<timeout<18000, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); | 39 | MODULE_PARM_DESC(timeout, |
40 | "Watchdog timeout in seconds. (0 < timeout < 18000, default=" | ||
41 | __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); | ||
40 | 42 | ||
41 | static int nowayout = WATCHDOG_NOWAYOUT; | 43 | static int nowayout = WATCHDOG_NOWAYOUT; |
42 | module_param(nowayout, int, 0); | 44 | module_param(nowayout, int, 0); |
43 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | 45 | MODULE_PARM_DESC(nowayout, |
46 | "Watchdog cannot be stopped once started (default=" | ||
47 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | ||
44 | 48 | ||
45 | /* | 49 | /* |
46 | * ali_start - start watchdog countdown | 50 | * ali_start - start watchdog countdown |
@@ -103,15 +107,16 @@ static void ali_keepalive(void) | |||
103 | 107 | ||
104 | static int ali_settimer(int t) | 108 | static int ali_settimer(int t) |
105 | { | 109 | { |
106 | if(t < 0) | 110 | if (t < 0) |
107 | return -EINVAL; | 111 | return -EINVAL; |
108 | else if(t < 60) | 112 | else if (t < 60) |
109 | ali_timeout_bits = t|(1<<6); | 113 | ali_timeout_bits = t|(1<<6); |
110 | else if(t < 3600) | 114 | else if (t < 3600) |
111 | ali_timeout_bits = (t/60)|(1<<7); | 115 | ali_timeout_bits = (t/60)|(1<<7); |
112 | else if(t < 18000) | 116 | else if (t < 18000) |
113 | ali_timeout_bits = (t/300)|(1<<6)|(1<<7); | 117 | ali_timeout_bits = (t/300)|(1<<6)|(1<<7); |
114 | else return -EINVAL; | 118 | else |
119 | return -EINVAL; | ||
115 | 120 | ||
116 | timeout = t; | 121 | timeout = t; |
117 | return 0; | 122 | return 0; |
@@ -134,21 +139,22 @@ static int ali_settimer(int t) | |||
134 | */ | 139 | */ |
135 | 140 | ||
136 | static ssize_t ali_write(struct file *file, const char __user *data, | 141 | static ssize_t ali_write(struct file *file, const char __user *data, |
137 | size_t len, loff_t * ppos) | 142 | size_t len, loff_t *ppos) |
138 | { | 143 | { |
139 | /* See if we got the magic character 'V' and reload the timer */ | 144 | /* See if we got the magic character 'V' and reload the timer */ |
140 | if (len) { | 145 | if (len) { |
141 | if (!nowayout) { | 146 | if (!nowayout) { |
142 | size_t i; | 147 | size_t i; |
143 | 148 | ||
144 | /* note: just in case someone wrote the magic character | 149 | /* note: just in case someone wrote the |
145 | * five months ago... */ | 150 | magic character five months ago... */ |
146 | ali_expect_release = 0; | 151 | ali_expect_release = 0; |
147 | 152 | ||
148 | /* scan to see whether or not we got the magic character */ | 153 | /* scan to see whether or not we got |
154 | the magic character */ | ||
149 | for (i = 0; i != len; i++) { | 155 | for (i = 0; i != len; i++) { |
150 | char c; | 156 | char c; |
151 | if(get_user(c, data+i)) | 157 | if (get_user(c, data+i)) |
152 | return -EFAULT; | 158 | return -EFAULT; |
153 | if (c == 'V') | 159 | if (c == 'V') |
154 | ali_expect_release = 42; | 160 | ali_expect_release = 42; |
@@ -163,7 +169,6 @@ static ssize_t ali_write(struct file *file, const char __user *data, | |||
163 | 169 | ||
164 | /* | 170 | /* |
165 | * ali_ioctl - handle watchdog ioctls | 171 | * ali_ioctl - handle watchdog ioctls |
166 | * @inode: VFS inode | ||
167 | * @file: VFS file pointer | 172 | * @file: VFS file pointer |
168 | * @cmd: ioctl number | 173 | * @cmd: ioctl number |
169 | * @arg: arguments to the ioctl | 174 | * @arg: arguments to the ioctl |
@@ -172,8 +177,7 @@ static ssize_t ali_write(struct file *file, const char __user *data, | |||
172 | * we want an extension to enable irq ack monitoring and the like | 177 | * we want an extension to enable irq ack monitoring and the like |
173 | */ | 178 | */ |
174 | 179 | ||
175 | static int ali_ioctl(struct inode *inode, struct file *file, | 180 | static long ali_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
176 | unsigned int cmd, unsigned long arg) | ||
177 | { | 181 | { |
178 | void __user *argp = (void __user *)arg; | 182 | void __user *argp = (void __user *)arg; |
179 | int __user *p = argp; | 183 | int __user *p = argp; |
@@ -186,57 +190,45 @@ static int ali_ioctl(struct inode *inode, struct file *file, | |||
186 | }; | 190 | }; |
187 | 191 | ||
188 | switch (cmd) { | 192 | switch (cmd) { |
189 | case WDIOC_GETSUPPORT: | 193 | case WDIOC_GETSUPPORT: |
190 | return copy_to_user(argp, &ident, | 194 | return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; |
191 | sizeof (ident)) ? -EFAULT : 0; | ||
192 | |||
193 | case WDIOC_GETSTATUS: | ||
194 | case WDIOC_GETBOOTSTATUS: | ||
195 | return put_user(0, p); | ||
196 | |||
197 | case WDIOC_KEEPALIVE: | ||
198 | ali_keepalive(); | ||
199 | return 0; | ||
200 | |||
201 | case WDIOC_SETOPTIONS: | ||
202 | { | ||
203 | int new_options, retval = -EINVAL; | ||
204 | |||
205 | if (get_user (new_options, p)) | ||
206 | return -EFAULT; | ||
207 | |||
208 | if (new_options & WDIOS_DISABLECARD) { | ||
209 | ali_stop(); | ||
210 | retval = 0; | ||
211 | } | ||
212 | |||
213 | if (new_options & WDIOS_ENABLECARD) { | ||
214 | ali_start(); | ||
215 | retval = 0; | ||
216 | } | ||
217 | 195 | ||
218 | return retval; | 196 | case WDIOC_GETSTATUS: |
197 | case WDIOC_GETBOOTSTATUS: | ||
198 | return put_user(0, p); | ||
199 | case WDIOC_KEEPALIVE: | ||
200 | ali_keepalive(); | ||
201 | return 0; | ||
202 | case WDIOC_SETOPTIONS: | ||
203 | { | ||
204 | int new_options, retval = -EINVAL; | ||
205 | |||
206 | if (get_user(new_options, p)) | ||
207 | return -EFAULT; | ||
208 | if (new_options & WDIOS_DISABLECARD) { | ||
209 | ali_stop(); | ||
210 | retval = 0; | ||
219 | } | 211 | } |
220 | 212 | if (new_options & WDIOS_ENABLECARD) { | |
221 | case WDIOC_SETTIMEOUT: | 213 | ali_start(); |
222 | { | 214 | retval = 0; |
223 | int new_timeout; | ||
224 | |||
225 | if (get_user(new_timeout, p)) | ||
226 | return -EFAULT; | ||
227 | |||
228 | if (ali_settimer(new_timeout)) | ||
229 | return -EINVAL; | ||
230 | |||
231 | ali_keepalive(); | ||
232 | /* Fall */ | ||
233 | } | 215 | } |
234 | 216 | return retval; | |
235 | case WDIOC_GETTIMEOUT: | 217 | } |
236 | return put_user(timeout, p); | 218 | case WDIOC_SETTIMEOUT: |
237 | 219 | { | |
238 | default: | 220 | int new_timeout; |
239 | return -ENOTTY; | 221 | if (get_user(new_timeout, p)) |
222 | return -EFAULT; | ||
223 | if (ali_settimer(new_timeout)) | ||
224 | return -EINVAL; | ||
225 | ali_keepalive(); | ||
226 | /* Fall */ | ||
227 | } | ||
228 | case WDIOC_GETTIMEOUT: | ||
229 | return put_user(timeout, p); | ||
230 | default: | ||
231 | return -ENOTTY; | ||
240 | } | 232 | } |
241 | } | 233 | } |
242 | 234 | ||
@@ -274,10 +266,11 @@ static int ali_release(struct inode *inode, struct file *file) | |||
274 | /* | 266 | /* |
275 | * Shut off the timer. | 267 | * Shut off the timer. |
276 | */ | 268 | */ |
277 | if (ali_expect_release == 42) { | 269 | if (ali_expect_release == 42) |
278 | ali_stop(); | 270 | ali_stop(); |
279 | } else { | 271 | else { |
280 | printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); | 272 | printk(KERN_CRIT PFX |
273 | "Unexpected close, not stopping watchdog!\n"); | ||
281 | ali_keepalive(); | 274 | ali_keepalive(); |
282 | } | 275 | } |
283 | clear_bit(0, &ali_is_open); | 276 | clear_bit(0, &ali_is_open); |
@@ -292,13 +285,11 @@ static int ali_release(struct inode *inode, struct file *file) | |||
292 | */ | 285 | */ |
293 | 286 | ||
294 | 287 | ||
295 | static int ali_notify_sys(struct notifier_block *this, unsigned long code, void *unused) | 288 | static int ali_notify_sys(struct notifier_block *this, |
289 | unsigned long code, void *unused) | ||
296 | { | 290 | { |
297 | if (code==SYS_DOWN || code==SYS_HALT) { | 291 | if (code == SYS_DOWN || code == SYS_HALT) |
298 | /* Turn the WDT off */ | 292 | ali_stop(); /* Turn the WDT off */ |
299 | ali_stop(); | ||
300 | } | ||
301 | |||
302 | return NOTIFY_DONE; | 293 | return NOTIFY_DONE; |
303 | } | 294 | } |
304 | 295 | ||
@@ -340,10 +331,10 @@ static int __init ali_find_watchdog(void) | |||
340 | 331 | ||
341 | /* Check for the a 7101 PMU */ | 332 | /* Check for the a 7101 PMU */ |
342 | pdev = pci_get_device(PCI_VENDOR_ID_AL, 0x7101, NULL); | 333 | pdev = pci_get_device(PCI_VENDOR_ID_AL, 0x7101, NULL); |
343 | if(pdev == NULL) | 334 | if (pdev == NULL) |
344 | return -ENODEV; | 335 | return -ENODEV; |
345 | 336 | ||
346 | if(pci_enable_device(pdev)) { | 337 | if (pci_enable_device(pdev)) { |
347 | pci_dev_put(pdev); | 338 | pci_dev_put(pdev); |
348 | return -EIO; | 339 | return -EIO; |
349 | } | 340 | } |
@@ -355,9 +346,12 @@ static int __init ali_find_watchdog(void) | |||
355 | */ | 346 | */ |
356 | pci_read_config_dword(pdev, 0xCC, &wdog); | 347 | pci_read_config_dword(pdev, 0xCC, &wdog); |
357 | 348 | ||
358 | wdog &= ~0x3F; /* Timer bits */ | 349 | /* Timer bits */ |
359 | wdog &= ~((1<<27)|(1<<26)|(1<<25)|(1<<24)); /* Issued events */ | 350 | wdog &= ~0x3F; |
360 | wdog &= ~((1<<16)|(1<<13)|(1<<12)|(1<<11)|(1<<10)|(1<<9)); /* No monitor bits */ | 351 | /* Issued events */ |
352 | wdog &= ~((1<<27)|(1<<26)|(1<<25)|(1<<24)); | ||
353 | /* No monitor bits */ | ||
354 | wdog &= ~((1<<16)|(1<<13)|(1<<12)|(1<<11)|(1<<10)|(1<<9)); | ||
361 | 355 | ||
362 | pci_write_config_dword(pdev, 0xCC, wdog); | 356 | pci_write_config_dword(pdev, 0xCC, wdog); |
363 | 357 | ||
@@ -369,12 +363,12 @@ static int __init ali_find_watchdog(void) | |||
369 | */ | 363 | */ |
370 | 364 | ||
371 | static const struct file_operations ali_fops = { | 365 | static const struct file_operations ali_fops = { |
372 | .owner = THIS_MODULE, | 366 | .owner = THIS_MODULE, |
373 | .llseek = no_llseek, | 367 | .llseek = no_llseek, |
374 | .write = ali_write, | 368 | .write = ali_write, |
375 | .ioctl = ali_ioctl, | 369 | .unlocked_ioctl = ali_ioctl, |
376 | .open = ali_open, | 370 | .open = ali_open, |
377 | .release = ali_release, | 371 | .release = ali_release, |
378 | }; | 372 | }; |
379 | 373 | ||
380 | static struct miscdevice ali_miscdev = { | 374 | static struct miscdevice ali_miscdev = { |
@@ -399,15 +393,16 @@ static int __init watchdog_init(void) | |||
399 | int ret; | 393 | int ret; |
400 | 394 | ||
401 | /* Check whether or not the hardware watchdog is there */ | 395 | /* Check whether or not the hardware watchdog is there */ |
402 | if (ali_find_watchdog() != 0) { | 396 | if (ali_find_watchdog() != 0) |
403 | return -ENODEV; | 397 | return -ENODEV; |
404 | } | ||
405 | 398 | ||
406 | /* Check that the timeout value is within it's range ; if not reset to the default */ | 399 | /* Check that the timeout value is within it's range; |
400 | if not reset to the default */ | ||
407 | if (timeout < 1 || timeout >= 18000) { | 401 | if (timeout < 1 || timeout >= 18000) { |
408 | timeout = WATCHDOG_TIMEOUT; | 402 | timeout = WATCHDOG_TIMEOUT; |
409 | printk(KERN_INFO PFX "timeout value must be 0<timeout<18000, using %d\n", | 403 | printk(KERN_INFO PFX |
410 | timeout); | 404 | "timeout value must be 0 < timeout < 18000, using %d\n", |
405 | timeout); | ||
411 | } | 406 | } |
412 | 407 | ||
413 | /* Calculate the watchdog's timeout */ | 408 | /* Calculate the watchdog's timeout */ |
@@ -415,15 +410,16 @@ static int __init watchdog_init(void) | |||
415 | 410 | ||
416 | ret = register_reboot_notifier(&ali_notifier); | 411 | ret = register_reboot_notifier(&ali_notifier); |
417 | if (ret != 0) { | 412 | if (ret != 0) { |
418 | printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", | 413 | printk(KERN_ERR PFX |
419 | ret); | 414 | "cannot register reboot notifier (err=%d)\n", ret); |
420 | goto out; | 415 | goto out; |
421 | } | 416 | } |
422 | 417 | ||
423 | ret = misc_register(&ali_miscdev); | 418 | ret = misc_register(&ali_miscdev); |
424 | if (ret != 0) { | 419 | if (ret != 0) { |
425 | printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", | 420 | printk(KERN_ERR PFX |
426 | WATCHDOG_MINOR, ret); | 421 | "cannot register miscdev on minor=%d (err=%d)\n", |
422 | WATCHDOG_MINOR, ret); | ||
427 | goto unreg_reboot; | 423 | goto unreg_reboot; |
428 | } | 424 | } |
429 | 425 | ||