diff options
-rw-r--r-- | drivers/watchdog/i6300esb.c | 342 |
1 files changed, 167 insertions, 175 deletions
diff --git a/drivers/watchdog/i6300esb.c b/drivers/watchdog/i6300esb.c index ca44fd9b19bb..01a283f7a271 100644 --- a/drivers/watchdog/i6300esb.c +++ b/drivers/watchdog/i6300esb.c | |||
@@ -38,9 +38,8 @@ | |||
38 | #include <linux/init.h> | 38 | #include <linux/init.h> |
39 | #include <linux/pci.h> | 39 | #include <linux/pci.h> |
40 | #include <linux/ioport.h> | 40 | #include <linux/ioport.h> |
41 | 41 | #include <linux/uaccess.h> | |
42 | #include <asm/uaccess.h> | 42 | #include <linux/io.h> |
43 | #include <asm/io.h> | ||
44 | 43 | ||
45 | /* Module and version information */ | 44 | /* Module and version information */ |
46 | #define ESB_VERSION "0.03" | 45 | #define ESB_VERSION "0.03" |
@@ -59,17 +58,17 @@ | |||
59 | #define ESB_RELOAD_REG BASEADDR + 0x0c /* Reload register */ | 58 | #define ESB_RELOAD_REG BASEADDR + 0x0c /* Reload register */ |
60 | 59 | ||
61 | /* Lock register bits */ | 60 | /* Lock register bits */ |
62 | #define ESB_WDT_FUNC ( 0x01 << 2 ) /* Watchdog functionality */ | 61 | #define ESB_WDT_FUNC (0x01 << 2) /* Watchdog functionality */ |
63 | #define ESB_WDT_ENABLE ( 0x01 << 1 ) /* Enable WDT */ | 62 | #define ESB_WDT_ENABLE (0x01 << 1) /* Enable WDT */ |
64 | #define ESB_WDT_LOCK ( 0x01 << 0 ) /* Lock (nowayout) */ | 63 | #define ESB_WDT_LOCK (0x01 << 0) /* Lock (nowayout) */ |
65 | 64 | ||
66 | /* Config register bits */ | 65 | /* Config register bits */ |
67 | #define ESB_WDT_REBOOT ( 0x01 << 5 ) /* Enable reboot on timeout */ | 66 | #define ESB_WDT_REBOOT (0x01 << 5) /* Enable reboot on timeout */ |
68 | #define ESB_WDT_FREQ ( 0x01 << 2 ) /* Decrement frequency */ | 67 | #define ESB_WDT_FREQ (0x01 << 2) /* Decrement frequency */ |
69 | #define ESB_WDT_INTTYPE ( 0x11 << 0 ) /* Interrupt type on timer1 timeout */ | 68 | #define ESB_WDT_INTTYPE (0x11 << 0) /* Interrupt type on timer1 timeout */ |
70 | 69 | ||
71 | /* Reload register bits */ | 70 | /* Reload register bits */ |
72 | #define ESB_WDT_RELOAD ( 0x01 << 8 ) /* prevent timeout */ | 71 | #define ESB_WDT_RELOAD (0x01 << 8) /* prevent timeout */ |
73 | 72 | ||
74 | /* Magic constants */ | 73 | /* Magic constants */ |
75 | #define ESB_UNLOCK1 0x80 /* Step 1 to unlock reset registers */ | 74 | #define ESB_UNLOCK1 0x80 /* Step 1 to unlock reset registers */ |
@@ -84,14 +83,20 @@ static unsigned short triggered; /* The status of the watchdog upon boot */ | |||
84 | static char esb_expect_close; | 83 | static char esb_expect_close; |
85 | 84 | ||
86 | /* module parameters */ | 85 | /* module parameters */ |
87 | #define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat (1<heartbeat<2*1023) */ | 86 | /* 30 sec default heartbeat (1 < heartbeat < 2*1023) */ |
87 | #define WATCHDOG_HEARTBEAT 30 | ||
88 | static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */ | 88 | static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */ |
89 | |||
89 | module_param(heartbeat, int, 0); | 90 | module_param(heartbeat, int, 0); |
90 | MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (1<heartbeat<2046, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); | 91 | MODULE_PARM_DESC(heartbeat, |
92 | "Watchdog heartbeat in seconds. (1<heartbeat<2046, default=" | ||
93 | __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); | ||
91 | 94 | ||
92 | static int nowayout = WATCHDOG_NOWAYOUT; | 95 | static int nowayout = WATCHDOG_NOWAYOUT; |
93 | module_param(nowayout, int, 0); | 96 | module_param(nowayout, int, 0); |
94 | 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) ")"); | ||
95 | 100 | ||
96 | /* | 101 | /* |
97 | * Some i6300ESB specific functions | 102 | * Some i6300ESB specific functions |
@@ -104,8 +109,8 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" _ | |||
104 | * to once before they need to be unlocked again. | 109 | * to once before they need to be unlocked again. |
105 | */ | 110 | */ |
106 | static inline void esb_unlock_registers(void) { | 111 | static inline void esb_unlock_registers(void) { |
107 | writeb(ESB_UNLOCK1, ESB_RELOAD_REG); | 112 | writeb(ESB_UNLOCK1, ESB_RELOAD_REG); |
108 | writeb(ESB_UNLOCK2, ESB_RELOAD_REG); | 113 | writeb(ESB_UNLOCK2, ESB_RELOAD_REG); |
109 | } | 114 | } |
110 | 115 | ||
111 | static void esb_timer_start(void) | 116 | static void esb_timer_start(void) |
@@ -114,8 +119,7 @@ static void esb_timer_start(void) | |||
114 | 119 | ||
115 | /* Enable or Enable + Lock? */ | 120 | /* Enable or Enable + Lock? */ |
116 | val = 0x02 | (nowayout ? 0x01 : 0x00); | 121 | val = 0x02 | (nowayout ? 0x01 : 0x00); |
117 | 122 | pci_write_config_byte(esb_pci, ESB_LOCK_REG, val); | |
118 | pci_write_config_byte(esb_pci, ESB_LOCK_REG, val); | ||
119 | } | 123 | } |
120 | 124 | ||
121 | static int esb_timer_stop(void) | 125 | static int esb_timer_stop(void) |
@@ -140,7 +144,7 @@ static void esb_timer_keepalive(void) | |||
140 | spin_lock(&esb_lock); | 144 | spin_lock(&esb_lock); |
141 | esb_unlock_registers(); | 145 | esb_unlock_registers(); |
142 | writew(ESB_WDT_RELOAD, ESB_RELOAD_REG); | 146 | writew(ESB_WDT_RELOAD, ESB_RELOAD_REG); |
143 | /* FIXME: Do we need to flush anything here? */ | 147 | /* FIXME: Do we need to flush anything here? */ |
144 | spin_unlock(&esb_lock); | 148 | spin_unlock(&esb_lock); |
145 | } | 149 | } |
146 | 150 | ||
@@ -167,7 +171,7 @@ static int esb_timer_set_heartbeat(int time) | |||
167 | esb_unlock_registers(); | 171 | esb_unlock_registers(); |
168 | writel(val, ESB_TIMER2_REG); | 172 | writel(val, ESB_TIMER2_REG); |
169 | 173 | ||
170 | /* Reload */ | 174 | /* Reload */ |
171 | esb_unlock_registers(); | 175 | esb_unlock_registers(); |
172 | writew(ESB_WDT_RELOAD, ESB_RELOAD_REG); | 176 | writew(ESB_WDT_RELOAD, ESB_RELOAD_REG); |
173 | 177 | ||
@@ -179,54 +183,55 @@ static int esb_timer_set_heartbeat(int time) | |||
179 | return 0; | 183 | return 0; |
180 | } | 184 | } |
181 | 185 | ||
182 | static int esb_timer_read (void) | 186 | static int esb_timer_read(void) |
183 | { | 187 | { |
184 | u32 count; | 188 | u32 count; |
185 | 189 | ||
186 | /* This isn't documented, and doesn't take into | 190 | /* This isn't documented, and doesn't take into |
187 | * acount which stage is running, but it looks | 191 | * acount which stage is running, but it looks |
188 | * like a 20 bit count down, so we might as well report it. | 192 | * like a 20 bit count down, so we might as well report it. |
189 | */ | 193 | */ |
190 | pci_read_config_dword(esb_pci, 0x64, &count); | 194 | pci_read_config_dword(esb_pci, 0x64, &count); |
191 | return (int)count; | 195 | return (int)count; |
192 | } | 196 | } |
193 | 197 | ||
194 | /* | 198 | /* |
195 | * /dev/watchdog handling | 199 | * /dev/watchdog handling |
196 | */ | 200 | */ |
197 | 201 | ||
198 | static int esb_open (struct inode *inode, struct file *file) | 202 | static int esb_open(struct inode *inode, struct file *file) |
199 | { | 203 | { |
200 | /* /dev/watchdog can only be opened once */ | 204 | /* /dev/watchdog can only be opened once */ |
201 | if (test_and_set_bit(0, &timer_alive)) | 205 | if (test_and_set_bit(0, &timer_alive)) |
202 | return -EBUSY; | 206 | return -EBUSY; |
203 | 207 | ||
204 | /* Reload and activate timer */ | 208 | /* Reload and activate timer */ |
205 | esb_timer_keepalive (); | 209 | esb_timer_keepalive(); |
206 | esb_timer_start (); | 210 | esb_timer_start(); |
207 | 211 | ||
208 | return nonseekable_open(inode, file); | 212 | return nonseekable_open(inode, file); |
209 | } | 213 | } |
210 | 214 | ||
211 | static int esb_release (struct inode *inode, struct file *file) | 215 | static int esb_release(struct inode *inode, struct file *file) |
212 | { | 216 | { |
213 | /* Shut off the timer. */ | 217 | /* Shut off the timer. */ |
214 | if (esb_expect_close == 42) { | 218 | if (esb_expect_close == 42) |
215 | esb_timer_stop (); | 219 | esb_timer_stop(); |
216 | } else { | 220 | else { |
217 | printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); | 221 | printk(KERN_CRIT PFX |
218 | esb_timer_keepalive (); | 222 | "Unexpected close, not stopping watchdog!\n"); |
219 | } | 223 | esb_timer_keepalive(); |
220 | clear_bit(0, &timer_alive); | 224 | } |
221 | esb_expect_close = 0; | 225 | clear_bit(0, &timer_alive); |
222 | return 0; | 226 | esb_expect_close = 0; |
227 | return 0; | ||
223 | } | 228 | } |
224 | 229 | ||
225 | static ssize_t esb_write (struct file *file, const char __user *data, | 230 | static ssize_t esb_write(struct file *file, const char __user *data, |
226 | size_t len, loff_t * ppos) | 231 | size_t len, loff_t *ppos) |
227 | { | 232 | { |
228 | /* See if we got the magic character 'V' and reload the timer */ | 233 | /* See if we got the magic character 'V' and reload the timer */ |
229 | if (len) { | 234 | if (len) { |
230 | if (!nowayout) { | 235 | if (!nowayout) { |
231 | size_t i; | 236 | size_t i; |
232 | 237 | ||
@@ -237,7 +242,7 @@ static ssize_t esb_write (struct file *file, const char __user *data, | |||
237 | /* scan to see whether or not we got the magic character */ | 242 | /* scan to see whether or not we got the magic character */ |
238 | for (i = 0; i != len; i++) { | 243 | for (i = 0; i != len; i++) { |
239 | char c; | 244 | char c; |
240 | if(get_user(c, data+i)) | 245 | if (get_user(c, data+i)) |
241 | return -EFAULT; | 246 | return -EFAULT; |
242 | if (c == 'V') | 247 | if (c == 'V') |
243 | esb_expect_close = 42; | 248 | esb_expect_close = 42; |
@@ -245,13 +250,12 @@ static ssize_t esb_write (struct file *file, const char __user *data, | |||
245 | } | 250 | } |
246 | 251 | ||
247 | /* someone wrote to us, we should reload the timer */ | 252 | /* someone wrote to us, we should reload the timer */ |
248 | esb_timer_keepalive (); | 253 | esb_timer_keepalive(); |
249 | } | 254 | } |
250 | return len; | 255 | return len; |
251 | } | 256 | } |
252 | 257 | ||
253 | static int esb_ioctl (struct inode *inode, struct file *file, | 258 | static long esb_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
254 | unsigned int cmd, unsigned long arg) | ||
255 | { | 259 | { |
256 | int new_options, retval = -EINVAL; | 260 | int new_options, retval = -EINVAL; |
257 | int new_heartbeat; | 261 | int new_heartbeat; |
@@ -266,71 +270,65 @@ static int esb_ioctl (struct inode *inode, struct file *file, | |||
266 | }; | 270 | }; |
267 | 271 | ||
268 | switch (cmd) { | 272 | switch (cmd) { |
269 | case WDIOC_GETSUPPORT: | 273 | case WDIOC_GETSUPPORT: |
270 | return copy_to_user(argp, &ident, | 274 | return copy_to_user(argp, &ident, |
271 | sizeof (ident)) ? -EFAULT : 0; | 275 | sizeof(ident)) ? -EFAULT : 0; |
272 | |||
273 | case WDIOC_GETSTATUS: | ||
274 | return put_user (esb_timer_read(), p); | ||
275 | |||
276 | case WDIOC_GETBOOTSTATUS: | ||
277 | return put_user (triggered, p); | ||
278 | |||
279 | case WDIOC_KEEPALIVE: | ||
280 | esb_timer_keepalive (); | ||
281 | return 0; | ||
282 | 276 | ||
283 | case WDIOC_SETOPTIONS: | 277 | case WDIOC_GETSTATUS: |
284 | { | 278 | return put_user(esb_timer_read(), p); |
285 | if (get_user (new_options, p)) | ||
286 | return -EFAULT; | ||
287 | 279 | ||
288 | if (new_options & WDIOS_DISABLECARD) { | 280 | case WDIOC_GETBOOTSTATUS: |
289 | esb_timer_stop (); | 281 | return put_user(triggered, p); |
290 | retval = 0; | ||
291 | } | ||
292 | 282 | ||
293 | if (new_options & WDIOS_ENABLECARD) { | 283 | case WDIOC_KEEPALIVE: |
294 | esb_timer_keepalive (); | 284 | esb_timer_keepalive(); |
295 | esb_timer_start (); | 285 | return 0; |
296 | retval = 0; | ||
297 | } | ||
298 | 286 | ||
299 | return retval; | 287 | case WDIOC_SETOPTIONS: |
300 | } | 288 | { |
289 | if (get_user(new_options, p)) | ||
290 | return -EFAULT; | ||
301 | 291 | ||
302 | case WDIOC_SETTIMEOUT: | 292 | if (new_options & WDIOS_DISABLECARD) { |
303 | { | 293 | esb_timer_stop(); |
304 | if (get_user(new_heartbeat, p)) | 294 | retval = 0; |
305 | return -EFAULT; | 295 | } |
306 | |||
307 | if (esb_timer_set_heartbeat(new_heartbeat)) | ||
308 | return -EINVAL; | ||
309 | |||
310 | esb_timer_keepalive (); | ||
311 | /* Fall */ | ||
312 | } | ||
313 | |||
314 | case WDIOC_GETTIMEOUT: | ||
315 | return put_user(heartbeat, p); | ||
316 | 296 | ||
317 | default: | 297 | if (new_options & WDIOS_ENABLECARD) { |
318 | return -ENOTTY; | 298 | esb_timer_keepalive(); |
319 | } | 299 | esb_timer_start(); |
300 | retval = 0; | ||
301 | } | ||
302 | return retval; | ||
303 | } | ||
304 | case WDIOC_SETTIMEOUT: | ||
305 | { | ||
306 | if (get_user(new_heartbeat, p)) | ||
307 | return -EFAULT; | ||
308 | if (esb_timer_set_heartbeat(new_heartbeat)) | ||
309 | return -EINVAL; | ||
310 | esb_timer_keepalive(); | ||
311 | /* Fall */ | ||
312 | } | ||
313 | case WDIOC_GETTIMEOUT: | ||
314 | return put_user(heartbeat, p); | ||
315 | default: | ||
316 | return -ENOTTY; | ||
317 | } | ||
320 | } | 318 | } |
321 | 319 | ||
322 | /* | 320 | /* |
323 | * Notify system | 321 | * Notify system |
324 | */ | 322 | */ |
325 | 323 | ||
326 | static int esb_notify_sys (struct notifier_block *this, unsigned long code, void *unused) | 324 | static int esb_notify_sys(struct notifier_block *this, |
325 | unsigned long code, void *unused) | ||
327 | { | 326 | { |
328 | if (code==SYS_DOWN || code==SYS_HALT) { | 327 | if (code == SYS_DOWN || code == SYS_HALT) { |
329 | /* Turn the WDT off */ | 328 | /* Turn the WDT off */ |
330 | esb_timer_stop (); | 329 | esb_timer_stop(); |
331 | } | 330 | } |
332 | 331 | return NOTIFY_DONE; | |
333 | return NOTIFY_DONE; | ||
334 | } | 332 | } |
335 | 333 | ||
336 | /* | 334 | /* |
@@ -338,22 +336,22 @@ static int esb_notify_sys (struct notifier_block *this, unsigned long code, void | |||
338 | */ | 336 | */ |
339 | 337 | ||
340 | static const struct file_operations esb_fops = { | 338 | static const struct file_operations esb_fops = { |
341 | .owner = THIS_MODULE, | 339 | .owner = THIS_MODULE, |
342 | .llseek = no_llseek, | 340 | .llseek = no_llseek, |
343 | .write = esb_write, | 341 | .write = esb_write, |
344 | .ioctl = esb_ioctl, | 342 | .unlocked_ioctl = esb_ioctl, |
345 | .open = esb_open, | 343 | .open = esb_open, |
346 | .release = esb_release, | 344 | .release = esb_release, |
347 | }; | 345 | }; |
348 | 346 | ||
349 | static struct miscdevice esb_miscdev = { | 347 | static struct miscdevice esb_miscdev = { |
350 | .minor = WATCHDOG_MINOR, | 348 | .minor = WATCHDOG_MINOR, |
351 | .name = "watchdog", | 349 | .name = "watchdog", |
352 | .fops = &esb_fops, | 350 | .fops = &esb_fops, |
353 | }; | 351 | }; |
354 | 352 | ||
355 | static struct notifier_block esb_notifier = { | 353 | static struct notifier_block esb_notifier = { |
356 | .notifier_call = esb_notify_sys, | 354 | .notifier_call = esb_notify_sys, |
357 | }; | 355 | }; |
358 | 356 | ||
359 | /* | 357 | /* |
@@ -365,50 +363,44 @@ static struct notifier_block esb_notifier = { | |||
365 | * want to register another driver on the same PCI id. | 363 | * want to register another driver on the same PCI id. |
366 | */ | 364 | */ |
367 | static struct pci_device_id esb_pci_tbl[] = { | 365 | static struct pci_device_id esb_pci_tbl[] = { |
368 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_9), }, | 366 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_9), }, |
369 | { 0, }, /* End of list */ | 367 | { 0, }, /* End of list */ |
370 | }; | 368 | }; |
371 | MODULE_DEVICE_TABLE (pci, esb_pci_tbl); | 369 | MODULE_DEVICE_TABLE(pci, esb_pci_tbl); |
372 | 370 | ||
373 | /* | 371 | /* |
374 | * Init & exit routines | 372 | * Init & exit routines |
375 | */ | 373 | */ |
376 | 374 | ||
377 | static unsigned char __init esb_getdevice (void) | 375 | static unsigned char __init esb_getdevice(void) |
378 | { | 376 | { |
379 | u8 val1; | 377 | u8 val1; |
380 | unsigned short val2; | 378 | unsigned short val2; |
379 | /* | ||
380 | * Find the PCI device | ||
381 | */ | ||
381 | 382 | ||
382 | struct pci_dev *dev = NULL; | 383 | esb_pci = pci_get_device(PCI_VENDOR_ID_INTEL, |
383 | /* | 384 | PCI_DEVICE_ID_INTEL_ESB_9, NULL); |
384 | * Find the PCI device | ||
385 | */ | ||
386 | |||
387 | for_each_pci_dev(dev) { | ||
388 | if (pci_match_id(esb_pci_tbl, dev)) { | ||
389 | esb_pci = dev; | ||
390 | break; | ||
391 | } | ||
392 | } | ||
393 | 385 | ||
394 | if (esb_pci) { | 386 | if (esb_pci) { |
395 | if (pci_enable_device(esb_pci)) { | 387 | if (pci_enable_device(esb_pci)) { |
396 | printk (KERN_ERR PFX "failed to enable device\n"); | 388 | printk(KERN_ERR PFX "failed to enable device\n"); |
397 | goto err_devput; | 389 | goto err_devput; |
398 | } | 390 | } |
399 | 391 | ||
400 | if (pci_request_region(esb_pci, 0, ESB_MODULE_NAME)) { | 392 | if (pci_request_region(esb_pci, 0, ESB_MODULE_NAME)) { |
401 | printk (KERN_ERR PFX "failed to request region\n"); | 393 | printk(KERN_ERR PFX "failed to request region\n"); |
402 | goto err_disable; | 394 | goto err_disable; |
403 | } | 395 | } |
404 | 396 | ||
405 | BASEADDR = ioremap(pci_resource_start(esb_pci, 0), | 397 | BASEADDR = ioremap(pci_resource_start(esb_pci, 0), |
406 | pci_resource_len(esb_pci, 0)); | 398 | pci_resource_len(esb_pci, 0)); |
407 | if (BASEADDR == NULL) { | 399 | if (BASEADDR == NULL) { |
408 | /* Something's wrong here, BASEADDR has to be set */ | 400 | /* Something's wrong here, BASEADDR has to be set */ |
409 | printk (KERN_ERR PFX "failed to get BASEADDR\n"); | 401 | printk(KERN_ERR PFX "failed to get BASEADDR\n"); |
410 | goto err_release; | 402 | goto err_release; |
411 | } | 403 | } |
412 | 404 | ||
413 | /* | 405 | /* |
414 | * The watchdog has two timers, it can be setup so that the | 406 | * The watchdog has two timers, it can be setup so that the |
@@ -425,7 +417,7 @@ static unsigned char __init esb_getdevice (void) | |||
425 | /* Check that the WDT isn't already locked */ | 417 | /* Check that the WDT isn't already locked */ |
426 | pci_read_config_byte(esb_pci, ESB_LOCK_REG, &val1); | 418 | pci_read_config_byte(esb_pci, ESB_LOCK_REG, &val1); |
427 | if (val1 & ESB_WDT_LOCK) | 419 | if (val1 & ESB_WDT_LOCK) |
428 | printk (KERN_WARNING PFX "nowayout already set\n"); | 420 | printk(KERN_WARNING PFX "nowayout already set\n"); |
429 | 421 | ||
430 | /* Set the timer to watchdog mode and disable it for now */ | 422 | /* Set the timer to watchdog mode and disable it for now */ |
431 | pci_write_config_byte(esb_pci, ESB_LOCK_REG, 0x00); | 423 | pci_write_config_byte(esb_pci, ESB_LOCK_REG, 0x00); |
@@ -452,44 +444,44 @@ err_devput: | |||
452 | return 0; | 444 | return 0; |
453 | } | 445 | } |
454 | 446 | ||
455 | static int __init watchdog_init (void) | 447 | static int __init watchdog_init(void) |
456 | { | 448 | { |
457 | int ret; | 449 | int ret; |
458 | 450 | ||
459 | /* Check whether or not the hardware watchdog is there */ | 451 | /* Check whether or not the hardware watchdog is there */ |
460 | if (!esb_getdevice () || esb_pci == NULL) | 452 | if (!esb_getdevice() || esb_pci == NULL) |
461 | return -ENODEV; | 453 | return -ENODEV; |
462 | 454 | ||
463 | /* Check that the heartbeat value is within it's range ; if not reset to the default */ | 455 | /* Check that the heartbeat value is within it's range; |
464 | if (esb_timer_set_heartbeat (heartbeat)) { | 456 | if not reset to the default */ |
465 | esb_timer_set_heartbeat (WATCHDOG_HEARTBEAT); | 457 | if (esb_timer_set_heartbeat(heartbeat)) { |
466 | printk(KERN_INFO PFX "heartbeat value must be 1<heartbeat<2046, using %d\n", | 458 | esb_timer_set_heartbeat(WATCHDOG_HEARTBEAT); |
467 | heartbeat); | 459 | printk(KERN_INFO PFX |
468 | } | 460 | "heartbeat value must be 1<heartbeat<2046, using %d\n", |
469 | 461 | heartbeat); | |
470 | ret = register_reboot_notifier(&esb_notifier); | 462 | } |
471 | if (ret != 0) { | 463 | ret = register_reboot_notifier(&esb_notifier); |
472 | printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", | 464 | if (ret != 0) { |
473 | ret); | 465 | printk(KERN_ERR PFX |
474 | goto err_unmap; | 466 | "cannot register reboot notifier (err=%d)\n", ret); |
475 | } | 467 | goto err_unmap; |
476 | 468 | } | |
477 | ret = misc_register(&esb_miscdev); | ||
478 | if (ret != 0) { | ||
479 | printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", | ||
480 | WATCHDOG_MINOR, ret); | ||
481 | goto err_notifier; | ||
482 | } | ||
483 | |||
484 | esb_timer_stop (); | ||
485 | |||
486 | printk (KERN_INFO PFX "initialized (0x%p). heartbeat=%d sec (nowayout=%d)\n", | ||
487 | BASEADDR, heartbeat, nowayout); | ||
488 | 469 | ||
489 | return 0; | 470 | ret = misc_register(&esb_miscdev); |
471 | if (ret != 0) { | ||
472 | printk(KERN_ERR PFX | ||
473 | "cannot register miscdev on minor=%d (err=%d)\n", | ||
474 | WATCHDOG_MINOR, ret); | ||
475 | goto err_notifier; | ||
476 | } | ||
477 | esb_timer_stop(); | ||
478 | printk(KERN_INFO PFX | ||
479 | "initialized (0x%p). heartbeat=%d sec (nowayout=%d)\n", | ||
480 | BASEADDR, heartbeat, nowayout); | ||
481 | return 0; | ||
490 | 482 | ||
491 | err_notifier: | 483 | err_notifier: |
492 | unregister_reboot_notifier(&esb_notifier); | 484 | unregister_reboot_notifier(&esb_notifier); |
493 | err_unmap: | 485 | err_unmap: |
494 | iounmap(BASEADDR); | 486 | iounmap(BASEADDR); |
495 | /* err_release: */ | 487 | /* err_release: */ |
@@ -498,18 +490,18 @@ err_unmap: | |||
498 | pci_disable_device(esb_pci); | 490 | pci_disable_device(esb_pci); |
499 | /* err_devput: */ | 491 | /* err_devput: */ |
500 | pci_dev_put(esb_pci); | 492 | pci_dev_put(esb_pci); |
501 | return ret; | 493 | return ret; |
502 | } | 494 | } |
503 | 495 | ||
504 | static void __exit watchdog_cleanup (void) | 496 | static void __exit watchdog_cleanup(void) |
505 | { | 497 | { |
506 | /* Stop the timer before we leave */ | 498 | /* Stop the timer before we leave */ |
507 | if (!nowayout) | 499 | if (!nowayout) |
508 | esb_timer_stop (); | 500 | esb_timer_stop(); |
509 | 501 | ||
510 | /* Deregister */ | 502 | /* Deregister */ |
511 | misc_deregister(&esb_miscdev); | 503 | misc_deregister(&esb_miscdev); |
512 | unregister_reboot_notifier(&esb_notifier); | 504 | unregister_reboot_notifier(&esb_notifier); |
513 | iounmap(BASEADDR); | 505 | iounmap(BASEADDR); |
514 | pci_release_region(esb_pci, 0); | 506 | pci_release_region(esb_pci, 0); |
515 | pci_disable_device(esb_pci); | 507 | pci_disable_device(esb_pci); |