37
37
#include <linux/reboot.h>
38
38
#include <linux/init.h>
39
39
#include <linux/spinlock.h>
40
+ #include <linux/io.h>
41
+ #include <linux/uaccess.h>
40
42
41
- #include <asm/io.h>
42
- #include <asm/uaccess.h>
43
43
#include <asm/system.h>
44
44
45
45
#define WATCHDOG_NAME "w83627hf/thf/hg WDT"
@@ -57,22 +57,26 @@ MODULE_PARM_DESC(wdt_io, "w83627hf/thf WDT io port (default 0x2E)");
57
57
58
58
static int timeout = WATCHDOG_TIMEOUT ; /* in seconds */
59
59
module_param (timeout , int , 0 );
60
- MODULE_PARM_DESC (timeout , "Watchdog timeout in seconds. 1<= timeout <=255, default=" __MODULE_STRING (WATCHDOG_TIMEOUT ) "." );
60
+ MODULE_PARM_DESC (timeout ,
61
+ "Watchdog timeout in seconds. 1 <= timeout <= 255, default="
62
+ __MODULE_STRING (WATCHDOG_TIMEOUT ) "." );
61
63
62
64
static int nowayout = WATCHDOG_NOWAYOUT ;
63
65
module_param (nowayout , int , 0 );
64
- MODULE_PARM_DESC (nowayout , "Watchdog cannot be stopped once started (default=" __MODULE_STRING (WATCHDOG_NOWAYOUT ) ")" );
66
+ MODULE_PARM_DESC (nowayout ,
67
+ "Watchdog cannot be stopped once started (default="
68
+ __MODULE_STRING (WATCHDOG_NOWAYOUT ) ")" );
65
69
66
70
/*
67
71
* Kernel methods.
68
72
*/
69
73
70
74
#define WDT_EFER (wdt_io+0) /* Extended Function Enable Registers */
71
- #define WDT_EFIR (wdt_io+0) /* Extended Function Index Register (same as EFER) */
75
+ #define WDT_EFIR (wdt_io+0) /* Extended Function Index Register
76
+ (same as EFER) */
72
77
#define WDT_EFDR (WDT_EFIR+1) /* Extended Function Data Register */
73
78
74
- static void
75
- w83627hf_select_wd_register (void )
79
+ static void w83627hf_select_wd_register (void )
76
80
{
77
81
unsigned char c ;
78
82
outb_p (0x87 , WDT_EFER ); /* Enter extended function mode */
@@ -93,43 +97,45 @@ w83627hf_select_wd_register(void)
93
97
outb_p (0x01 , WDT_EFDR ); /* set bit 0 to activate GPIO2 */
94
98
}
95
99
96
- static void
97
- w83627hf_unselect_wd_register (void )
100
+ static void w83627hf_unselect_wd_register (void )
98
101
{
99
102
outb_p (0xAA , WDT_EFER ); /* Leave extended function mode */
100
103
}
101
104
102
105
/* tyan motherboards seem to set F5 to 0x4C ?
103
106
* So explicitly init to appropriate value. */
104
- static void
105
- w83627hf_init (void )
107
+
108
+ static void w83627hf_init (void )
106
109
{
107
110
unsigned char t ;
108
111
109
112
w83627hf_select_wd_register ();
110
113
111
114
outb_p (0xF6 , WDT_EFER ); /* Select CRF6 */
112
- t = inb_p (WDT_EFDR ); /* read CRF6 */
115
+ t = inb_p (WDT_EFDR ); /* read CRF6 */
113
116
if (t != 0 ) {
114
- printk (KERN_INFO PFX "Watchdog already running. Resetting timeout to %d sec\n" , timeout );
117
+ printk (KERN_INFO PFX
118
+ "Watchdog already running. Resetting timeout to %d sec\n" ,
119
+ timeout );
115
120
outb_p (timeout , WDT_EFDR ); /* Write back to CRF6 */
116
121
}
117
122
118
123
outb_p (0xF5 , WDT_EFER ); /* Select CRF5 */
119
- t = inb_p (WDT_EFDR ); /* read CRF5 */
120
- t &=~0x0C ; /* set second mode & disable keyboard turning off watchdog */
124
+ t = inb_p (WDT_EFDR ); /* read CRF5 */
125
+ t &= ~0x0C ; /* set second mode & disable keyboard
126
+ turning off watchdog */
121
127
outb_p (t , WDT_EFDR ); /* Write back to CRF5 */
122
128
123
129
outb_p (0xF7 , WDT_EFER ); /* Select CRF7 */
124
- t = inb_p (WDT_EFDR ); /* read CRF7 */
125
- t &=~0xC0 ; /* disable keyboard & mouse turning off watchdog */
130
+ t = inb_p (WDT_EFDR ); /* read CRF7 */
131
+ t &= ~0xC0 ; /* disable keyboard & mouse turning off
132
+ watchdog */
126
133
outb_p (t , WDT_EFDR ); /* Write back to CRF7 */
127
134
128
135
w83627hf_unselect_wd_register ();
129
136
}
130
137
131
- static void
132
- wdt_ctrl (int timeout )
138
+ static void wdt_ctrl (int timeout )
133
139
{
134
140
spin_lock (& io_lock );
135
141
@@ -143,32 +149,28 @@ wdt_ctrl(int timeout)
143
149
spin_unlock (& io_lock );
144
150
}
145
151
146
- static int
147
- wdt_ping (void )
152
+ static int wdt_ping (void )
148
153
{
149
154
wdt_ctrl (timeout );
150
155
return 0 ;
151
156
}
152
157
153
- static int
154
- wdt_disable (void )
158
+ static int wdt_disable (void )
155
159
{
156
160
wdt_ctrl (0 );
157
161
return 0 ;
158
162
}
159
163
160
- static int
161
- wdt_set_heartbeat (int t )
164
+ static int wdt_set_heartbeat (int t )
162
165
{
163
- if (( t < 1 ) || ( t > 255 ) )
166
+ if (t < 1 || t > 255 )
164
167
return - EINVAL ;
165
-
166
168
timeout = t ;
167
169
return 0 ;
168
170
}
169
171
170
- static ssize_t
171
- wdt_write ( struct file * file , const char __user * buf , size_t count , loff_t * ppos )
172
+ static ssize_t wdt_write ( struct file * file , const char __user * buf ,
173
+ size_t count , loff_t * ppos )
172
174
{
173
175
if (count ) {
174
176
if (!nowayout ) {
@@ -189,72 +191,61 @@ wdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
189
191
return count ;
190
192
}
191
193
192
- static int
193
- wdt_ioctl (struct inode * inode , struct file * file , unsigned int cmd ,
194
- unsigned long arg )
194
+ static long wdt_ioctl (struct file * file , unsigned int cmd , unsigned long arg )
195
195
{
196
196
void __user * argp = (void __user * )arg ;
197
197
int __user * p = argp ;
198
198
int new_timeout ;
199
199
static struct watchdog_info ident = {
200
- .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE ,
200
+ .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
201
+ WDIOF_MAGICCLOSE ,
201
202
.firmware_version = 1 ,
202
203
.identity = "W83627HF WDT" ,
203
204
};
204
205
205
206
switch (cmd ) {
206
207
case WDIOC_GETSUPPORT :
207
- if (copy_to_user (argp , & ident , sizeof (ident )))
208
- return - EFAULT ;
209
- break ;
210
-
208
+ if (copy_to_user (argp , & ident , sizeof (ident )))
209
+ return - EFAULT ;
210
+ break ;
211
211
case WDIOC_GETSTATUS :
212
212
case WDIOC_GETBOOTSTATUS :
213
- return put_user (0 , p );
214
-
213
+ return put_user (0 , p );
215
214
case WDIOC_KEEPALIVE :
216
- wdt_ping ();
217
- break ;
218
-
215
+ wdt_ping ();
216
+ break ;
219
217
case WDIOC_SETTIMEOUT :
220
- if (get_user (new_timeout , p ))
221
- return - EFAULT ;
222
- if (wdt_set_heartbeat (new_timeout ))
223
- return - EINVAL ;
224
- wdt_ping ();
225
- /* Fall */
226
-
218
+ if (get_user (new_timeout , p ))
219
+ return - EFAULT ;
220
+ if (wdt_set_heartbeat (new_timeout ))
221
+ return - EINVAL ;
222
+ wdt_ping ();
223
+ /* Fall */
227
224
case WDIOC_GETTIMEOUT :
228
- return put_user (timeout , p );
229
-
225
+ return put_user (timeout , p );
230
226
case WDIOC_SETOPTIONS :
231
227
{
232
- int options , retval = - EINVAL ;
233
-
234
- if (get_user (options , p ))
235
- return - EFAULT ;
236
-
237
- if (options & WDIOS_DISABLECARD ) {
238
- wdt_disable ();
239
- retval = 0 ;
240
- }
241
-
242
- if (options & WDIOS_ENABLECARD ) {
243
- wdt_ping ();
244
- retval = 0 ;
245
- }
228
+ int options , retval = - EINVAL ;
246
229
247
- return retval ;
230
+ if (get_user (options , p ))
231
+ return - EFAULT ;
232
+ if (options & WDIOS_DISABLECARD ) {
233
+ wdt_disable ();
234
+ retval = 0 ;
235
+ }
236
+ if (options & WDIOS_ENABLECARD ) {
237
+ wdt_ping ();
238
+ retval = 0 ;
239
+ }
240
+ return retval ;
248
241
}
249
-
250
242
default :
251
- return - ENOTTY ;
243
+ return - ENOTTY ;
252
244
}
253
245
return 0 ;
254
246
}
255
247
256
- static int
257
- wdt_open (struct inode * inode , struct file * file )
248
+ static int wdt_open (struct inode * inode , struct file * file )
258
249
{
259
250
if (test_and_set_bit (0 , & wdt_is_open ))
260
251
return - EBUSY ;
@@ -266,13 +257,13 @@ wdt_open(struct inode *inode, struct file *file)
266
257
return nonseekable_open (inode , file );
267
258
}
268
259
269
- static int
270
- wdt_close (struct inode * inode , struct file * file )
260
+ static int wdt_close (struct inode * inode , struct file * file )
271
261
{
272
- if (expect_close == 42 ) {
262
+ if (expect_close == 42 )
273
263
wdt_disable ();
274
- } else {
275
- printk (KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n" );
264
+ else {
265
+ printk (KERN_CRIT PFX
266
+ "Unexpected close, not stopping watchdog!\n" );
276
267
wdt_ping ();
277
268
}
278
269
expect_close = 0 ;
@@ -284,8 +275,7 @@ wdt_close(struct inode *inode, struct file *file)
284
275
* Notifier for system down
285
276
*/
286
277
287
- static int
288
- wdt_notify_sys (struct notifier_block * this , unsigned long code ,
278
+ static int wdt_notify_sys (struct notifier_block * this , unsigned long code ,
289
279
void * unused )
290
280
{
291
281
if (code == SYS_DOWN || code == SYS_HALT ) {
@@ -303,7 +293,7 @@ static const struct file_operations wdt_fops = {
303
293
.owner = THIS_MODULE ,
304
294
.llseek = no_llseek ,
305
295
.write = wdt_write ,
306
- .ioctl = wdt_ioctl ,
296
+ .unlocked_ioctl = wdt_ioctl ,
307
297
.open = wdt_open ,
308
298
.release = wdt_close ,
309
299
};
@@ -323,21 +313,21 @@ static struct notifier_block wdt_notifier = {
323
313
.notifier_call = wdt_notify_sys ,
324
314
};
325
315
326
- static int __init
327
- wdt_init (void )
316
+ static int __init wdt_init (void )
328
317
{
329
318
int ret ;
330
319
331
320
printk (KERN_INFO "WDT driver for the Winbond(TM) W83627HF/THF/HG Super I/O chip initialising.\n" );
332
321
333
322
if (wdt_set_heartbeat (timeout )) {
334
323
wdt_set_heartbeat (WATCHDOG_TIMEOUT );
335
- printk (KERN_INFO PFX "timeout value must be 1<=timeout<=255, using %d\n" ,
336
- WATCHDOG_TIMEOUT );
324
+ printk (KERN_INFO PFX
325
+ "timeout value must be 1 <= timeout <= 255, using %d\n" ,
326
+ WATCHDOG_TIMEOUT );
337
327
}
338
328
339
329
if (!request_region (wdt_io , 1 , WATCHDOG_NAME )) {
340
- printk (KERN_ERR PFX "I/O address 0x%04x already in use\n" ,
330
+ printk (KERN_ERR PFX "I/O address 0x%04x already in use\n" ,
341
331
wdt_io );
342
332
ret = - EIO ;
343
333
goto out ;
@@ -347,20 +337,22 @@ wdt_init(void)
347
337
348
338
ret = register_reboot_notifier (& wdt_notifier );
349
339
if (ret != 0 ) {
350
- printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n" ,
351
- ret );
340
+ printk (KERN_ERR PFX
341
+ "cannot register reboot notifier (err=%d)\n" , ret );
352
342
goto unreg_regions ;
353
343
}
354
344
355
345
ret = misc_register (& wdt_miscdev );
356
346
if (ret != 0 ) {
357
- printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n" ,
358
- WATCHDOG_MINOR , ret );
347
+ printk (KERN_ERR PFX
348
+ "cannot register miscdev on minor=%d (err=%d)\n" ,
349
+ WATCHDOG_MINOR , ret );
359
350
goto unreg_reboot ;
360
351
}
361
352
362
- printk (KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)\n" ,
363
- timeout , nowayout );
353
+ printk (KERN_INFO PFX
354
+ "initialized. timeout=%d sec (nowayout=%d)\n" ,
355
+ timeout , nowayout );
364
356
365
357
out :
366
358
return ret ;
@@ -371,12 +363,11 @@ wdt_init(void)
371
363
goto out ;
372
364
}
373
365
374
- static void __exit
375
- wdt_exit (void )
366
+ static void __exit wdt_exit (void )
376
367
{
377
368
misc_deregister (& wdt_miscdev );
378
369
unregister_reboot_notifier (& wdt_notifier );
379
- release_region (wdt_io ,1 );
370
+ release_region (wdt_io , 1 );
380
371
}
381
372
382
373
module_init (wdt_init );
0 commit comments