aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/watchdog
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2008-05-19 09:04:57 -0400
committerWim Van Sebroeck <wim@iguana.be>2008-05-27 11:22:43 -0400
commit173d95bc2e68baf73eb89fb9ef1cc63a66f581a5 (patch)
tree45cdc517f96a9574b54224f2a8fc9ff2c15284f4 /drivers/watchdog
parentb6b4d9b8d07e34f745871d3109c84894db29041b (diff)
[WATCHDOG 03/57] ali: watchdog locking and style
Clean up and check locking Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'drivers/watchdog')
-rw-r--r--drivers/watchdog/alim1535_wdt.c186
-rw-r--r--drivers/watchdog/alim7101_wdt.c224
2 files changed, 209 insertions, 201 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 @@
30static unsigned long ali_is_open; 30static unsigned long ali_is_open;
31static char ali_expect_release; 31static char ali_expect_release;
32static struct pci_dev *ali_pci; 32static struct pci_dev *ali_pci;
33static u32 ali_timeout_bits; /* stores the computed timeout */ 33static u32 ali_timeout_bits; /* stores the computed timeout */
34static DEFINE_SPINLOCK(ali_lock); /* Guards the hardware */ 34static DEFINE_SPINLOCK(ali_lock); /* Guards the hardware */
35 35
36/* module parameters */ 36/* module parameters */
37static int timeout = WATCHDOG_TIMEOUT; 37static int timeout = WATCHDOG_TIMEOUT;
38module_param(timeout, int, 0); 38module_param(timeout, int, 0);
39MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (0<timeout<18000, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); 39MODULE_PARM_DESC(timeout,
40 "Watchdog timeout in seconds. (0 < timeout < 18000, default="
41 __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
40 42
41static int nowayout = WATCHDOG_NOWAYOUT; 43static int nowayout = WATCHDOG_NOWAYOUT;
42module_param(nowayout, int, 0); 44module_param(nowayout, int, 0);
43MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 45MODULE_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
104static int ali_settimer(int t) 108static 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
136static ssize_t ali_write(struct file *file, const char __user *data, 141static 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
175static int ali_ioctl(struct inode *inode, struct file *file, 180static 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
295static int ali_notify_sys(struct notifier_block *this, unsigned long code, void *unused) 288static 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
371static const struct file_operations ali_fops = { 365static 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
380static struct miscdevice ali_miscdev = { 374static 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
diff --git a/drivers/watchdog/alim7101_wdt.c b/drivers/watchdog/alim7101_wdt.c
index 238273c98656..c495f36c6aa9 100644
--- a/drivers/watchdog/alim7101_wdt.c
+++ b/drivers/watchdog/alim7101_wdt.c
@@ -32,8 +32,8 @@
32#include <linux/fs.h> 32#include <linux/fs.h>
33#include <linux/pci.h> 33#include <linux/pci.h>
34 34
35#include <asm/io.h> 35#include <linux/io.h>
36#include <asm/uaccess.h> 36#include <linux/uaccess.h>
37#include <asm/system.h> 37#include <asm/system.h>
38 38
39#define OUR_NAME "alim7101_wdt" 39#define OUR_NAME "alim7101_wdt"
@@ -60,13 +60,17 @@
60 */ 60 */
61 61
62#define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */ 62#define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */
63static int timeout = WATCHDOG_TIMEOUT; /* in seconds, will be multiplied by HZ to get seconds to wait for a ping */ 63/* in seconds, will be multiplied by HZ to get seconds to wait for a ping */
64static int timeout = WATCHDOG_TIMEOUT;
64module_param(timeout, int, 0); 65module_param(timeout, int, 0);
65MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); 66MODULE_PARM_DESC(timeout,
67 "Watchdog timeout in seconds. (1<=timeout<=3600, default="
68 __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
66 69
67static int use_gpio = 0; /* Use the pic (for a1d revision alim7101) */ 70static int use_gpio; /* Use the pic (for a1d revision alim7101) */
68module_param(use_gpio, int, 0); 71module_param(use_gpio, int, 0);
69MODULE_PARM_DESC(use_gpio, "Use the gpio watchdog. (required by old cobalt boards)"); 72MODULE_PARM_DESC(use_gpio,
73 "Use the gpio watchdog (required by old cobalt boards).");
70 74
71static void wdt_timer_ping(unsigned long); 75static void wdt_timer_ping(unsigned long);
72static DEFINE_TIMER(timer, wdt_timer_ping, 0, 1); 76static DEFINE_TIMER(timer, wdt_timer_ping, 0, 1);
@@ -77,8 +81,9 @@ static struct pci_dev *alim7101_pmu;
77 81
78static int nowayout = WATCHDOG_NOWAYOUT; 82static int nowayout = WATCHDOG_NOWAYOUT;
79module_param(nowayout, int, 0); 83module_param(nowayout, int, 0);
80MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" 84MODULE_PARM_DESC(nowayout,
81 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 85 "Watchdog cannot be stopped once started (default="
86 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
82 87
83/* 88/*
84 * Whack the dog 89 * Whack the dog
@@ -89,23 +94,26 @@ static void wdt_timer_ping(unsigned long data)
89 /* If we got a heartbeat pulse within the WDT_US_INTERVAL 94 /* If we got a heartbeat pulse within the WDT_US_INTERVAL
90 * we agree to ping the WDT 95 * we agree to ping the WDT
91 */ 96 */
92 char tmp; 97 char tmp;
93 98
94 if(time_before(jiffies, next_heartbeat)) 99 if (time_before(jiffies, next_heartbeat)) {
95 {
96 /* Ping the WDT (this is actually a disarm/arm sequence) */ 100 /* Ping the WDT (this is actually a disarm/arm sequence) */
97 pci_read_config_byte(alim7101_pmu, 0x92, &tmp); 101 pci_read_config_byte(alim7101_pmu, 0x92, &tmp);
98 pci_write_config_byte(alim7101_pmu, ALI_7101_WDT, (tmp & ~ALI_WDT_ARM)); 102 pci_write_config_byte(alim7101_pmu,
99 pci_write_config_byte(alim7101_pmu, ALI_7101_WDT, (tmp | ALI_WDT_ARM)); 103 ALI_7101_WDT, (tmp & ~ALI_WDT_ARM));
104 pci_write_config_byte(alim7101_pmu,
105 ALI_7101_WDT, (tmp | ALI_WDT_ARM));
100 if (use_gpio) { 106 if (use_gpio) {
101 pci_read_config_byte(alim7101_pmu, ALI_7101_GPIO_O, &tmp); 107 pci_read_config_byte(alim7101_pmu,
102 pci_write_config_byte(alim7101_pmu, ALI_7101_GPIO_O, tmp 108 ALI_7101_GPIO_O, &tmp);
103 | 0x20); 109 pci_write_config_byte(alim7101_pmu,
104 pci_write_config_byte(alim7101_pmu, ALI_7101_GPIO_O, tmp 110 ALI_7101_GPIO_O, tmp | 0x20);
105 & ~0x20); 111 pci_write_config_byte(alim7101_pmu,
112 ALI_7101_GPIO_O, tmp & ~0x20);
106 } 113 }
107 } else { 114 } else {
108 printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n"); 115 printk(KERN_WARNING PFX
116 "Heartbeat lost! Will not ping the watchdog\n");
109 } 117 }
110 /* Re-set the timer interval */ 118 /* Re-set the timer interval */
111 mod_timer(&timer, jiffies + WDT_INTERVAL); 119 mod_timer(&timer, jiffies + WDT_INTERVAL);
@@ -121,17 +129,23 @@ static void wdt_change(int writeval)
121 129
122 pci_read_config_byte(alim7101_pmu, ALI_7101_WDT, &tmp); 130 pci_read_config_byte(alim7101_pmu, ALI_7101_WDT, &tmp);
123 if (writeval == WDT_ENABLE) { 131 if (writeval == WDT_ENABLE) {
124 pci_write_config_byte(alim7101_pmu, ALI_7101_WDT, (tmp | ALI_WDT_ARM)); 132 pci_write_config_byte(alim7101_pmu,
133 ALI_7101_WDT, (tmp | ALI_WDT_ARM));
125 if (use_gpio) { 134 if (use_gpio) {
126 pci_read_config_byte(alim7101_pmu, ALI_7101_GPIO_O, &tmp); 135 pci_read_config_byte(alim7101_pmu,
127 pci_write_config_byte(alim7101_pmu, ALI_7101_GPIO_O, tmp & ~0x20); 136 ALI_7101_GPIO_O, &tmp);
137 pci_write_config_byte(alim7101_pmu,
138 ALI_7101_GPIO_O, tmp & ~0x20);
128 } 139 }
129 140
130 } else { 141 } else {
131 pci_write_config_byte(alim7101_pmu, ALI_7101_WDT, (tmp & ~ALI_WDT_ARM)); 142 pci_write_config_byte(alim7101_pmu,
143 ALI_7101_WDT, (tmp & ~ALI_WDT_ARM));
132 if (use_gpio) { 144 if (use_gpio) {
133 pci_read_config_byte(alim7101_pmu, ALI_7101_GPIO_O, &tmp); 145 pci_read_config_byte(alim7101_pmu,
134 pci_write_config_byte(alim7101_pmu, ALI_7101_GPIO_O, tmp | 0x20); 146 ALI_7101_GPIO_O, &tmp);
147 pci_write_config_byte(alim7101_pmu,
148 ALI_7101_GPIO_O, tmp | 0x20);
135 } 149 }
136 } 150 }
137} 151}
@@ -169,10 +183,11 @@ static void wdt_keepalive(void)
169 * /dev/watchdog handling 183 * /dev/watchdog handling
170 */ 184 */
171 185
172static ssize_t fop_write(struct file * file, const char __user * buf, size_t count, loff_t * ppos) 186static ssize_t fop_write(struct file *file, const char __user *buf,
187 size_t count, loff_t *ppos)
173{ 188{
174 /* See if we got the magic character 'V' and reload the timer */ 189 /* See if we got the magic character 'V' and reload the timer */
175 if(count) { 190 if (count) {
176 if (!nowayout) { 191 if (!nowayout) {
177 size_t ofs; 192 size_t ofs;
178 193
@@ -195,119 +210,116 @@ static ssize_t fop_write(struct file * file, const char __user * buf, size_t cou
195 return count; 210 return count;
196} 211}
197 212
198static int fop_open(struct inode * inode, struct file * file) 213static int fop_open(struct inode *inode, struct file *file)
199{ 214{
200 /* Just in case we're already talking to someone... */ 215 /* Just in case we're already talking to someone... */
201 if(test_and_set_bit(0, &wdt_is_open)) 216 if (test_and_set_bit(0, &wdt_is_open))
202 return -EBUSY; 217 return -EBUSY;
203 /* Good, fire up the show */ 218 /* Good, fire up the show */
204 wdt_startup(); 219 wdt_startup();
205 return nonseekable_open(inode, file); 220 return nonseekable_open(inode, file);
206} 221}
207 222
208static int fop_close(struct inode * inode, struct file * file) 223static int fop_close(struct inode *inode, struct file *file)
209{ 224{
210 if(wdt_expect_close == 42) 225 if (wdt_expect_close == 42)
211 wdt_turnoff(); 226 wdt_turnoff();
212 else { 227 else {
213 /* wim: shouldn't there be a: del_timer(&timer); */ 228 /* wim: shouldn't there be a: del_timer(&timer); */
214 printk(KERN_CRIT PFX "device file closed unexpectedly. Will not stop the WDT!\n"); 229 printk(KERN_CRIT PFX
230 "device file closed unexpectedly. Will not stop the WDT!\n");
215 } 231 }
216 clear_bit(0, &wdt_is_open); 232 clear_bit(0, &wdt_is_open);
217 wdt_expect_close = 0; 233 wdt_expect_close = 0;
218 return 0; 234 return 0;
219} 235}
220 236
221static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 237static long fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
222{ 238{
223 void __user *argp = (void __user *)arg; 239 void __user *argp = (void __user *)arg;
224 int __user *p = argp; 240 int __user *p = argp;
225 static struct watchdog_info ident = 241 static struct watchdog_info ident = {
226 { 242 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT
227 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, 243 | WDIOF_MAGICCLOSE,
228 .firmware_version = 1, 244 .firmware_version = 1,
229 .identity = "ALiM7101", 245 .identity = "ALiM7101",
230 }; 246 };
231 247
232 switch(cmd) 248 switch (cmd) {
249 case WDIOC_GETSUPPORT:
250 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
251 case WDIOC_GETSTATUS:
252 case WDIOC_GETBOOTSTATUS:
253 return put_user(0, p);
254 case WDIOC_KEEPALIVE:
255 wdt_keepalive();
256 return 0;
257 case WDIOC_SETOPTIONS:
233 { 258 {
234 case WDIOC_GETSUPPORT: 259 int new_options, retval = -EINVAL;
235 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
236 case WDIOC_GETSTATUS:
237 case WDIOC_GETBOOTSTATUS:
238 return put_user(0, p);
239 case WDIOC_KEEPALIVE:
240 wdt_keepalive();
241 return 0;
242 case WDIOC_SETOPTIONS:
243 {
244 int new_options, retval = -EINVAL;
245
246 if(get_user(new_options, p))
247 return -EFAULT;
248
249 if(new_options & WDIOS_DISABLECARD) {
250 wdt_turnoff();
251 retval = 0;
252 }
253
254 if(new_options & WDIOS_ENABLECARD) {
255 wdt_startup();
256 retval = 0;
257 }
258 260
259 return retval; 261 if (get_user(new_options, p))
262 return -EFAULT;
263 if (new_options & WDIOS_DISABLECARD) {
264 wdt_turnoff();
265 retval = 0;
260 } 266 }
261 case WDIOC_SETTIMEOUT: 267 if (new_options & WDIOS_ENABLECARD) {
262 { 268 wdt_startup();
263 int new_timeout; 269 retval = 0;
264
265 if(get_user(new_timeout, p))
266 return -EFAULT;
267
268 if(new_timeout < 1 || new_timeout > 3600) /* arbitrary upper limit */
269 return -EINVAL;
270
271 timeout = new_timeout;
272 wdt_keepalive();
273 /* Fall through */
274 } 270 }
275 case WDIOC_GETTIMEOUT: 271 return retval;
276 return put_user(timeout, p); 272 }
277 default: 273 case WDIOC_SETTIMEOUT:
278 return -ENOTTY; 274 {
275 int new_timeout;
276
277 if (get_user(new_timeout, p))
278 return -EFAULT;
279 /* arbitrary upper limit */
280 if (new_timeout < 1 || new_timeout > 3600)
281 return -EINVAL;
282 timeout = new_timeout;
283 wdt_keepalive();
284 /* Fall through */
285 }
286 case WDIOC_GETTIMEOUT:
287 return put_user(timeout, p);
288 default:
289 return -ENOTTY;
279 } 290 }
280} 291}
281 292
282static const struct file_operations wdt_fops = { 293static const struct file_operations wdt_fops = {
283 .owner= THIS_MODULE, 294 .owner = THIS_MODULE,
284 .llseek= no_llseek, 295 .llseek = no_llseek,
285 .write= fop_write, 296 .write = fop_write,
286 .open= fop_open, 297 .open = fop_open,
287 .release= fop_close, 298 .release = fop_close,
288 .ioctl= fop_ioctl, 299 .unlocked_ioctl = fop_ioctl,
289}; 300};
290 301
291static struct miscdevice wdt_miscdev = { 302static struct miscdevice wdt_miscdev = {
292 .minor=WATCHDOG_MINOR, 303 .minor = WATCHDOG_MINOR,
293 .name="watchdog", 304 .name = "watchdog",
294 .fops=&wdt_fops, 305 .fops = &wdt_fops,
295}; 306};
296 307
297/* 308/*
298 * Notifier for system down 309 * Notifier for system down
299 */ 310 */
300 311
301static int wdt_notify_sys(struct notifier_block *this, unsigned long code, void *unused) 312static int wdt_notify_sys(struct notifier_block *this,
313 unsigned long code, void *unused)
302{ 314{
303 if (code==SYS_DOWN || code==SYS_HALT) 315 if (code == SYS_DOWN || code == SYS_HALT)
304 wdt_turnoff(); 316 wdt_turnoff();
305 317
306 if (code==SYS_RESTART) { 318 if (code == SYS_RESTART) {
307 /* 319 /*
308 * Cobalt devices have no way of rebooting themselves other than 320 * Cobalt devices have no way of rebooting themselves other
309 * getting the watchdog to pull reset, so we restart the watchdog on 321 * than getting the watchdog to pull reset, so we restart the
310 * reboot with no heartbeat 322 * watchdog on reboot with no heartbeat
311 */ 323 */
312 wdt_change(WDT_ENABLE); 324 wdt_change(WDT_ENABLE);
313 printk(KERN_INFO PFX "Watchdog timer is now enabled with no heartbeat - should reboot in ~1 second.\n"); 325 printk(KERN_INFO PFX "Watchdog timer is now enabled with no heartbeat - should reboot in ~1 second.\n");
@@ -320,8 +332,7 @@ static int wdt_notify_sys(struct notifier_block *this, unsigned long code, void
320 * turn the timebomb registers off. 332 * turn the timebomb registers off.
321 */ 333 */
322 334
323static struct notifier_block wdt_notifier= 335static struct notifier_block wdt_notifier = {
324{
325 .notifier_call = wdt_notify_sys, 336 .notifier_call = wdt_notify_sys,
326}; 337};
327 338
@@ -354,7 +365,8 @@ static int __init alim7101_wdt_init(void)
354 ali1543_south = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, 365 ali1543_south = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533,
355 NULL); 366 NULL);
356 if (!ali1543_south) { 367 if (!ali1543_south) {
357 printk(KERN_INFO PFX "ALi 1543 South-Bridge not present - WDT not set\n"); 368 printk(KERN_INFO PFX
369 "ALi 1543 South-Bridge not present - WDT not set\n");
358 goto err_out; 370 goto err_out;
359 } 371 }
360 pci_read_config_byte(ali1543_south, 0x5e, &tmp); 372 pci_read_config_byte(ali1543_south, 0x5e, &tmp);
@@ -363,24 +375,25 @@ static int __init alim7101_wdt_init(void)
363 if (!use_gpio) { 375 if (!use_gpio) {
364 printk(KERN_INFO PFX "Detected old alim7101 revision 'a1d'. If this is a cobalt board, set the 'use_gpio' module parameter.\n"); 376 printk(KERN_INFO PFX "Detected old alim7101 revision 'a1d'. If this is a cobalt board, set the 'use_gpio' module parameter.\n");
365 goto err_out; 377 goto err_out;
366 } 378 }
367 nowayout = 1; 379 nowayout = 1;
368 } else if ((tmp & 0x1e) != 0x12 && (tmp & 0x1e) != 0x00) { 380 } else if ((tmp & 0x1e) != 0x12 && (tmp & 0x1e) != 0x00) {
369 printk(KERN_INFO PFX "ALi 1543 South-Bridge does not have the correct revision number (???1001?) - WDT not set\n"); 381 printk(KERN_INFO PFX "ALi 1543 South-Bridge does not have the correct revision number (???1001?) - WDT not set\n");
370 goto err_out; 382 goto err_out;
371 } 383 }
372 384
373 if(timeout < 1 || timeout > 3600) /* arbitrary upper limit */ 385 if (timeout < 1 || timeout > 3600) {
374 { 386 /* arbitrary upper limit */
375 timeout = WATCHDOG_TIMEOUT; 387 timeout = WATCHDOG_TIMEOUT;
376 printk(KERN_INFO PFX "timeout value must be 1<=x<=3600, using %d\n", 388 printk(KERN_INFO PFX
377 timeout); 389 "timeout value must be 1 <= x <= 3600, using %d\n",
390 timeout);
378 } 391 }
379 392
380 rc = register_reboot_notifier(&wdt_notifier); 393 rc = register_reboot_notifier(&wdt_notifier);
381 if (rc) { 394 if (rc) {
382 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", 395 printk(KERN_ERR PFX
383 rc); 396 "cannot register reboot notifier (err=%d)\n", rc);
384 goto err_out; 397 goto err_out;
385 } 398 }
386 399
@@ -391,9 +404,8 @@ static int __init alim7101_wdt_init(void)
391 goto err_out_reboot; 404 goto err_out_reboot;
392 } 405 }
393 406
394 if (nowayout) { 407 if (nowayout)
395 __module_get(THIS_MODULE); 408 __module_get(THIS_MODULE);
396 }
397 409
398 printk(KERN_INFO PFX "WDT driver for ALi M7101 initialised. timeout=%d sec (nowayout=%d)\n", 410 printk(KERN_INFO PFX "WDT driver for ALi M7101 initialised. timeout=%d sec (nowayout=%d)\n",
399 timeout, nowayout); 411 timeout, nowayout);