diff options
Diffstat (limited to 'drivers/watchdog/i6300esb.c')
-rw-r--r-- | drivers/watchdog/i6300esb.c | 366 |
1 files changed, 179 insertions, 187 deletions
diff --git a/drivers/watchdog/i6300esb.c b/drivers/watchdog/i6300esb.c index ca44fd9b19bb..c13383f7fcb9 100644 --- a/drivers/watchdog/i6300esb.c +++ b/drivers/watchdog/i6300esb.c | |||
@@ -9,18 +9,18 @@ | |||
9 | * as published by the Free Software Foundation; either version | 9 | * as published by the Free Software Foundation; either version |
10 | * 2 of the License, or (at your option) any later version. | 10 | * 2 of the License, or (at your option) any later version. |
11 | * | 11 | * |
12 | * based on i810-tco.c which is in turn based on softdog.c | 12 | * based on i810-tco.c which is in turn based on softdog.c |
13 | * | 13 | * |
14 | * The timer is implemented in the following I/O controller hubs: | 14 | * The timer is implemented in the following I/O controller hubs: |
15 | * (See the intel documentation on http://developer.intel.com.) | 15 | * (See the intel documentation on http://developer.intel.com.) |
16 | * 6300ESB chip : document number 300641-003 | 16 | * 6300ESB chip : document number 300641-003 |
17 | * | 17 | * |
18 | * 2004YYZZ Ross Biro | 18 | * 2004YYZZ Ross Biro |
19 | * Initial version 0.01 | 19 | * Initial version 0.01 |
20 | * 2004YYZZ Ross Biro | 20 | * 2004YYZZ Ross Biro |
21 | * Version 0.02 | 21 | * Version 0.02 |
22 | * 20050210 David Härdeman <david@2gen.com> | 22 | * 20050210 David Härdeman <david@2gen.com> |
23 | * Ported driver to kernel 2.6 | 23 | * Ported driver to kernel 2.6 |
24 | */ | 24 | */ |
25 | 25 | ||
26 | /* | 26 | /* |
@@ -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 |
@@ -103,9 +108,10 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" _ | |||
103 | * reload register. After this the appropriate registers can be written | 108 | * reload register. After this the appropriate registers can be written |
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 | { |
108 | writeb(ESB_UNLOCK2, ESB_RELOAD_REG); | 113 | writeb(ESB_UNLOCK1, ESB_RELOAD_REG); |
114 | writeb(ESB_UNLOCK2, ESB_RELOAD_REG); | ||
109 | } | 115 | } |
110 | 116 | ||
111 | static void esb_timer_start(void) | 117 | static void esb_timer_start(void) |
@@ -114,8 +120,7 @@ static void esb_timer_start(void) | |||
114 | 120 | ||
115 | /* Enable or Enable + Lock? */ | 121 | /* Enable or Enable + Lock? */ |
116 | val = 0x02 | (nowayout ? 0x01 : 0x00); | 122 | val = 0x02 | (nowayout ? 0x01 : 0x00); |
117 | 123 | pci_write_config_byte(esb_pci, ESB_LOCK_REG, val); | |
118 | pci_write_config_byte(esb_pci, ESB_LOCK_REG, val); | ||
119 | } | 124 | } |
120 | 125 | ||
121 | static int esb_timer_stop(void) | 126 | static int esb_timer_stop(void) |
@@ -140,7 +145,7 @@ static void esb_timer_keepalive(void) | |||
140 | spin_lock(&esb_lock); | 145 | spin_lock(&esb_lock); |
141 | esb_unlock_registers(); | 146 | esb_unlock_registers(); |
142 | writew(ESB_WDT_RELOAD, ESB_RELOAD_REG); | 147 | writew(ESB_WDT_RELOAD, ESB_RELOAD_REG); |
143 | /* FIXME: Do we need to flush anything here? */ | 148 | /* FIXME: Do we need to flush anything here? */ |
144 | spin_unlock(&esb_lock); | 149 | spin_unlock(&esb_lock); |
145 | } | 150 | } |
146 | 151 | ||
@@ -165,9 +170,9 @@ static int esb_timer_set_heartbeat(int time) | |||
165 | 170 | ||
166 | /* Write timer 2 */ | 171 | /* Write timer 2 */ |
167 | esb_unlock_registers(); | 172 | esb_unlock_registers(); |
168 | writel(val, ESB_TIMER2_REG); | 173 | writel(val, ESB_TIMER2_REG); |
169 | 174 | ||
170 | /* Reload */ | 175 | /* Reload */ |
171 | esb_unlock_registers(); | 176 | esb_unlock_registers(); |
172 | writew(ESB_WDT_RELOAD, ESB_RELOAD_REG); | 177 | writew(ESB_WDT_RELOAD, ESB_RELOAD_REG); |
173 | 178 | ||
@@ -179,54 +184,55 @@ static int esb_timer_set_heartbeat(int time) | |||
179 | return 0; | 184 | return 0; |
180 | } | 185 | } |
181 | 186 | ||
182 | static int esb_timer_read (void) | 187 | static int esb_timer_read(void) |
183 | { | 188 | { |
184 | u32 count; | 189 | u32 count; |
185 | 190 | ||
186 | /* This isn't documented, and doesn't take into | 191 | /* This isn't documented, and doesn't take into |
187 | * acount which stage is running, but it looks | 192 | * acount which stage is running, but it looks |
188 | * like a 20 bit count down, so we might as well report it. | 193 | * like a 20 bit count down, so we might as well report it. |
189 | */ | 194 | */ |
190 | pci_read_config_dword(esb_pci, 0x64, &count); | 195 | pci_read_config_dword(esb_pci, 0x64, &count); |
191 | return (int)count; | 196 | return (int)count; |
192 | } | 197 | } |
193 | 198 | ||
194 | /* | 199 | /* |
195 | * /dev/watchdog handling | 200 | * /dev/watchdog handling |
196 | */ | 201 | */ |
197 | 202 | ||
198 | static int esb_open (struct inode *inode, struct file *file) | 203 | static int esb_open(struct inode *inode, struct file *file) |
199 | { | 204 | { |
200 | /* /dev/watchdog can only be opened once */ | 205 | /* /dev/watchdog can only be opened once */ |
201 | if (test_and_set_bit(0, &timer_alive)) | 206 | if (test_and_set_bit(0, &timer_alive)) |
202 | return -EBUSY; | 207 | return -EBUSY; |
203 | 208 | ||
204 | /* Reload and activate timer */ | 209 | /* Reload and activate timer */ |
205 | esb_timer_keepalive (); | 210 | esb_timer_keepalive(); |
206 | esb_timer_start (); | 211 | esb_timer_start(); |
207 | 212 | ||
208 | return nonseekable_open(inode, file); | 213 | return nonseekable_open(inode, file); |
209 | } | 214 | } |
210 | 215 | ||
211 | static int esb_release (struct inode *inode, struct file *file) | 216 | static int esb_release(struct inode *inode, struct file *file) |
212 | { | 217 | { |
213 | /* Shut off the timer. */ | 218 | /* Shut off the timer. */ |
214 | if (esb_expect_close == 42) { | 219 | if (esb_expect_close == 42) |
215 | esb_timer_stop (); | 220 | esb_timer_stop(); |
216 | } else { | 221 | else { |
217 | printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); | 222 | printk(KERN_CRIT PFX |
218 | esb_timer_keepalive (); | 223 | "Unexpected close, not stopping watchdog!\n"); |
219 | } | 224 | esb_timer_keepalive(); |
220 | clear_bit(0, &timer_alive); | 225 | } |
221 | esb_expect_close = 0; | 226 | clear_bit(0, &timer_alive); |
222 | return 0; | 227 | esb_expect_close = 0; |
228 | return 0; | ||
223 | } | 229 | } |
224 | 230 | ||
225 | static ssize_t esb_write (struct file *file, const char __user *data, | 231 | static ssize_t esb_write(struct file *file, const char __user *data, |
226 | size_t len, loff_t * ppos) | 232 | size_t len, loff_t *ppos) |
227 | { | 233 | { |
228 | /* See if we got the magic character 'V' and reload the timer */ | 234 | /* See if we got the magic character 'V' and reload the timer */ |
229 | if (len) { | 235 | if (len) { |
230 | if (!nowayout) { | 236 | if (!nowayout) { |
231 | size_t i; | 237 | size_t i; |
232 | 238 | ||
@@ -237,7 +243,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 */ | 243 | /* scan to see whether or not we got the magic character */ |
238 | for (i = 0; i != len; i++) { | 244 | for (i = 0; i != len; i++) { |
239 | char c; | 245 | char c; |
240 | if(get_user(c, data+i)) | 246 | if (get_user(c, data + i)) |
241 | return -EFAULT; | 247 | return -EFAULT; |
242 | if (c == 'V') | 248 | if (c == 'V') |
243 | esb_expect_close = 42; | 249 | esb_expect_close = 42; |
@@ -245,92 +251,84 @@ static ssize_t esb_write (struct file *file, const char __user *data, | |||
245 | } | 251 | } |
246 | 252 | ||
247 | /* someone wrote to us, we should reload the timer */ | 253 | /* someone wrote to us, we should reload the timer */ |
248 | esb_timer_keepalive (); | 254 | esb_timer_keepalive(); |
249 | } | 255 | } |
250 | return len; | 256 | return len; |
251 | } | 257 | } |
252 | 258 | ||
253 | static int esb_ioctl (struct inode *inode, struct file *file, | 259 | static long esb_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
254 | unsigned int cmd, unsigned long arg) | ||
255 | { | 260 | { |
256 | int new_options, retval = -EINVAL; | 261 | int new_options, retval = -EINVAL; |
257 | int new_heartbeat; | 262 | int new_heartbeat; |
258 | void __user *argp = (void __user *)arg; | 263 | void __user *argp = (void __user *)arg; |
259 | int __user *p = argp; | 264 | int __user *p = argp; |
260 | static struct watchdog_info ident = { | 265 | static struct watchdog_info ident = { |
261 | .options = WDIOF_SETTIMEOUT | | 266 | .options = WDIOF_SETTIMEOUT | |
262 | WDIOF_KEEPALIVEPING | | 267 | WDIOF_KEEPALIVEPING | |
263 | WDIOF_MAGICCLOSE, | 268 | WDIOF_MAGICCLOSE, |
264 | .firmware_version = 0, | 269 | .firmware_version = 0, |
265 | .identity = ESB_MODULE_NAME, | 270 | .identity = ESB_MODULE_NAME, |
266 | }; | 271 | }; |
267 | 272 | ||
268 | switch (cmd) { | 273 | switch (cmd) { |
269 | case WDIOC_GETSUPPORT: | 274 | case WDIOC_GETSUPPORT: |
270 | return copy_to_user(argp, &ident, | 275 | return copy_to_user(argp, &ident, |
271 | sizeof (ident)) ? -EFAULT : 0; | 276 | 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 | 277 | ||
279 | case WDIOC_KEEPALIVE: | 278 | case WDIOC_GETSTATUS: |
280 | esb_timer_keepalive (); | 279 | return put_user(esb_timer_read(), p); |
281 | return 0; | ||
282 | 280 | ||
283 | case WDIOC_SETOPTIONS: | 281 | case WDIOC_GETBOOTSTATUS: |
284 | { | 282 | return put_user(triggered, p); |
285 | if (get_user (new_options, p)) | ||
286 | return -EFAULT; | ||
287 | 283 | ||
288 | if (new_options & WDIOS_DISABLECARD) { | 284 | case WDIOC_SETOPTIONS: |
289 | esb_timer_stop (); | 285 | { |
290 | retval = 0; | 286 | if (get_user(new_options, p)) |
291 | } | 287 | return -EFAULT; |
292 | 288 | ||
293 | if (new_options & WDIOS_ENABLECARD) { | 289 | if (new_options & WDIOS_DISABLECARD) { |
294 | esb_timer_keepalive (); | 290 | esb_timer_stop(); |
295 | esb_timer_start (); | 291 | retval = 0; |
296 | retval = 0; | 292 | } |
297 | } | ||
298 | |||
299 | return retval; | ||
300 | } | ||
301 | |||
302 | case WDIOC_SETTIMEOUT: | ||
303 | { | ||
304 | if (get_user(new_heartbeat, p)) | ||
305 | return -EFAULT; | ||
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 | 293 | ||
317 | default: | 294 | if (new_options & WDIOS_ENABLECARD) { |
318 | return -ENOTTY; | 295 | esb_timer_keepalive(); |
319 | } | 296 | esb_timer_start(); |
297 | retval = 0; | ||
298 | } | ||
299 | return retval; | ||
300 | } | ||
301 | case WDIOC_KEEPALIVE: | ||
302 | esb_timer_keepalive(); | ||
303 | return 0; | ||
304 | |||
305 | case WDIOC_SETTIMEOUT: | ||
306 | { | ||
307 | if (get_user(new_heartbeat, p)) | ||
308 | return -EFAULT; | ||
309 | if (esb_timer_set_heartbeat(new_heartbeat)) | ||
310 | return -EINVAL; | ||
311 | esb_timer_keepalive(); | ||
312 | /* Fall */ | ||
313 | } | ||
314 | case WDIOC_GETTIMEOUT: | ||
315 | return put_user(heartbeat, p); | ||
316 | default: | ||
317 | return -ENOTTY; | ||
318 | } | ||
320 | } | 319 | } |
321 | 320 | ||
322 | /* | 321 | /* |
323 | * Notify system | 322 | * Notify system |
324 | */ | 323 | */ |
325 | 324 | ||
326 | static int esb_notify_sys (struct notifier_block *this, unsigned long code, void *unused) | 325 | static int esb_notify_sys(struct notifier_block *this, |
326 | unsigned long code, void *unused) | ||
327 | { | 327 | { |
328 | if (code==SYS_DOWN || code==SYS_HALT) { | 328 | if (code == SYS_DOWN || code == SYS_HALT) |
329 | /* Turn the WDT off */ | 329 | esb_timer_stop(); /* Turn the WDT off */ |
330 | esb_timer_stop (); | ||
331 | } | ||
332 | 330 | ||
333 | return NOTIFY_DONE; | 331 | 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); |