diff options
Diffstat (limited to 'drivers/watchdog/alim7101_wdt.c')
-rw-r--r-- | drivers/watchdog/alim7101_wdt.c | 224 |
1 files changed, 118 insertions, 106 deletions
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 */ |
63 | static 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 */ |
64 | static int timeout = WATCHDOG_TIMEOUT; | ||
64 | module_param(timeout, int, 0); | 65 | module_param(timeout, int, 0); |
65 | MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); | 66 | MODULE_PARM_DESC(timeout, |
67 | "Watchdog timeout in seconds. (1<=timeout<=3600, default=" | ||
68 | __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); | ||
66 | 69 | ||
67 | static int use_gpio = 0; /* Use the pic (for a1d revision alim7101) */ | 70 | static int use_gpio; /* Use the pic (for a1d revision alim7101) */ |
68 | module_param(use_gpio, int, 0); | 71 | module_param(use_gpio, int, 0); |
69 | MODULE_PARM_DESC(use_gpio, "Use the gpio watchdog. (required by old cobalt boards)"); | 72 | MODULE_PARM_DESC(use_gpio, |
73 | "Use the gpio watchdog (required by old cobalt boards)."); | ||
70 | 74 | ||
71 | static void wdt_timer_ping(unsigned long); | 75 | static void wdt_timer_ping(unsigned long); |
72 | static DEFINE_TIMER(timer, wdt_timer_ping, 0, 1); | 76 | static DEFINE_TIMER(timer, wdt_timer_ping, 0, 1); |
@@ -77,8 +81,9 @@ static struct pci_dev *alim7101_pmu; | |||
77 | 81 | ||
78 | static int nowayout = WATCHDOG_NOWAYOUT; | 82 | static int nowayout = WATCHDOG_NOWAYOUT; |
79 | module_param(nowayout, int, 0); | 83 | module_param(nowayout, int, 0); |
80 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" | 84 | MODULE_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 | ||
172 | static ssize_t fop_write(struct file * file, const char __user * buf, size_t count, loff_t * ppos) | 186 | static 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 | ||
198 | static int fop_open(struct inode * inode, struct file * file) | 213 | static 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 | ||
208 | static int fop_close(struct inode * inode, struct file * file) | 223 | static 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 | ||
221 | static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) | 237 | static 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 | ||
282 | static const struct file_operations wdt_fops = { | 293 | static 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 | ||
291 | static struct miscdevice wdt_miscdev = { | 302 | static 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 | ||
301 | static int wdt_notify_sys(struct notifier_block *this, unsigned long code, void *unused) | 312 | static 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 | ||
323 | static struct notifier_block wdt_notifier= | 335 | static 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); |