Blame view
drivers/watchdog/pc87413_wdt.c
14 KB
789fc0adb [WATCHDOG] NS pc8... |
1 2 3 |
/* * NS pc87413-wdt Watchdog Timer driver for Linux 2.6.x.x * |
00b3b3e66 [WATCHDOG] NS pc8... |
4 |
* This code is based on wdt.c with original copyright. |
789fc0adb [WATCHDOG] NS pc8... |
5 |
* |
00b3b3e66 [WATCHDOG] NS pc8... |
6 7 |
* (C) Copyright 2006 Sven Anders, <anders@anduras.de> * and Marcus Junker, <junker@anduras.de> |
789fc0adb [WATCHDOG] NS pc8... |
8 9 10 11 12 13 |
* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * |
00b3b3e66 [WATCHDOG] NS pc8... |
14 |
* Neither Sven Anders, Marcus Junker nor ANDURAS AG |
789fc0adb [WATCHDOG] NS pc8... |
15 16 17 |
* admit liability nor provide warranty for any of this software. * This material is provided "AS-IS" and at no charge. * |
00b3b3e66 [WATCHDOG] NS pc8... |
18 |
* Release 1.1 |
789fc0adb [WATCHDOG] NS pc8... |
19 |
*/ |
27c766aaa watchdog: Use pr_... |
20 |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
789fc0adb [WATCHDOG] NS pc8... |
21 22 23 24 25 26 27 28 29 30 31 32 |
#include <linux/module.h> #include <linux/types.h> #include <linux/miscdevice.h> #include <linux/watchdog.h> #include <linux/ioport.h> #include <linux/delay.h> #include <linux/notifier.h> #include <linux/fs.h> #include <linux/reboot.h> #include <linux/init.h> #include <linux/spinlock.h> #include <linux/moduleparam.h> |
aee334c23 [WATCHDOG 31/57] ... |
33 34 |
#include <linux/io.h> #include <linux/uaccess.h> |
789fc0adb [WATCHDOG] NS pc8... |
35 |
|
789fc0adb [WATCHDOG] NS pc8... |
36 |
|
00b3b3e66 [WATCHDOG] NS pc8... |
37 |
/* #define DEBUG 1 */ |
789fc0adb [WATCHDOG] NS pc8... |
38 |
|
7944d3a5a [WATCHDOG] more c... |
39 |
#define DEFAULT_TIMEOUT 1 /* 1 minute */ |
00b3b3e66 [WATCHDOG] NS pc8... |
40 |
#define MAX_TIMEOUT 255 |
789fc0adb [WATCHDOG] NS pc8... |
41 |
|
00b3b3e66 [WATCHDOG] NS pc8... |
42 43 |
#define VERSION "1.1" #define MODNAME "pc87413 WDT" |
00b3b3e66 [WATCHDOG] NS pc8... |
44 |
#define DPFX MODNAME " - DEBUG: " |
789fc0adb [WATCHDOG] NS pc8... |
45 |
|
7944d3a5a [WATCHDOG] more c... |
46 |
#define WDT_INDEX_IO_PORT (io+0) /* I/O port base (index register) */ |
00b3b3e66 [WATCHDOG] NS pc8... |
47 48 |
#define WDT_DATA_IO_PORT (WDT_INDEX_IO_PORT+1) #define SWC_LDN 0x04 |
7944d3a5a [WATCHDOG] more c... |
49 |
#define SIOCFG2 0x22 /* Serial IO register */ |
25985edce Fix common misspe... |
50 |
#define WDCTL 0x10 /* Watchdog-Timer-Control-Register */ |
7944d3a5a [WATCHDOG] more c... |
51 52 |
#define WDTO 0x11 /* Watchdog timeout register */ #define WDCFG 0x12 /* Watchdog config register */ |
789fc0adb [WATCHDOG] NS pc8... |
53 |
|
76550d329 watchdog: fix sev... |
54 55 56 |
#define IO_DEFAULT 0x2E /* Address used on Portwell Boards */ static int io = IO_DEFAULT; |
7ccdb9467 watchdog: pc87413... |
57 |
static int swc_base_addr = -1; |
789fc0adb [WATCHDOG] NS pc8... |
58 |
|
7944d3a5a [WATCHDOG] more c... |
59 |
static int timeout = DEFAULT_TIMEOUT; /* timeout value */ |
aee334c23 [WATCHDOG 31/57] ... |
60 |
static unsigned long timer_enabled; /* is the timer enabled? */ |
789fc0adb [WATCHDOG] NS pc8... |
61 |
|
aee334c23 [WATCHDOG 31/57] ... |
62 |
static char expect_close; /* is the close expected? */ |
789fc0adb [WATCHDOG] NS pc8... |
63 |
|
aee334c23 [WATCHDOG 31/57] ... |
64 |
static DEFINE_SPINLOCK(io_lock); /* to guard us from io races */ |
789fc0adb [WATCHDOG] NS pc8... |
65 |
|
86a1e1896 watchdog: nowayou... |
66 |
static bool nowayout = WATCHDOG_NOWAYOUT; |
789fc0adb [WATCHDOG] NS pc8... |
67 |
|
00b3b3e66 [WATCHDOG] NS pc8... |
68 |
/* -- Low level function ----------------------------------------*/ |
789fc0adb [WATCHDOG] NS pc8... |
69 |
|
00b3b3e66 [WATCHDOG] NS pc8... |
70 |
/* Select pins for Watchdog output */ |
789fc0adb [WATCHDOG] NS pc8... |
71 |
|
aee334c23 [WATCHDOG 31/57] ... |
72 |
static inline void pc87413_select_wdt_out(void) |
789fc0adb [WATCHDOG] NS pc8... |
73 |
{ |
00b3b3e66 [WATCHDOG] NS pc8... |
74 |
unsigned int cr_data = 0; |
789fc0adb [WATCHDOG] NS pc8... |
75 |
|
00b3b3e66 [WATCHDOG] NS pc8... |
76 |
/* Step 1: Select multiple pin,pin55,as WDT output */ |
789fc0adb [WATCHDOG] NS pc8... |
77 78 |
outb_p(SIOCFG2, WDT_INDEX_IO_PORT); |
aee334c23 [WATCHDOG 31/57] ... |
79 |
cr_data = inb(WDT_DATA_IO_PORT); |
789fc0adb [WATCHDOG] NS pc8... |
80 81 82 83 84 |
cr_data |= 0x80; /* Set Bit7 to 1*/ outb_p(SIOCFG2, WDT_INDEX_IO_PORT); outb_p(cr_data, WDT_DATA_IO_PORT); |
00b3b3e66 [WATCHDOG] NS pc8... |
85 |
#ifdef DEBUG |
27c766aaa watchdog: Use pr_... |
86 |
pr_info(DPFX |
aee334c23 [WATCHDOG 31/57] ... |
87 88 89 |
"Select multiple pin,pin55,as WDT output: Bit7 to 1: %d ", cr_data); |
00b3b3e66 [WATCHDOG] NS pc8... |
90 |
#endif |
789fc0adb [WATCHDOG] NS pc8... |
91 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
92 |
/* Enable SWC functions */ |
789fc0adb [WATCHDOG] NS pc8... |
93 |
|
00b3b3e66 [WATCHDOG] NS pc8... |
94 95 |
static inline void pc87413_enable_swc(void) { |
aee334c23 [WATCHDOG 31/57] ... |
96 |
unsigned int cr_data = 0; |
789fc0adb [WATCHDOG] NS pc8... |
97 98 |
/* Step 2: Enable SWC functions */ |
7944d3a5a [WATCHDOG] more c... |
99 |
outb_p(0x07, WDT_INDEX_IO_PORT); /* Point SWC_LDN (LDN=4) */ |
789fc0adb [WATCHDOG] NS pc8... |
100 |
outb_p(SWC_LDN, WDT_DATA_IO_PORT); |
7944d3a5a [WATCHDOG] more c... |
101 |
outb_p(0x30, WDT_INDEX_IO_PORT); /* Read Index 0x30 First */ |
00b3b3e66 [WATCHDOG] NS pc8... |
102 |
cr_data = inb(WDT_DATA_IO_PORT); |
7944d3a5a [WATCHDOG] more c... |
103 |
cr_data |= 0x01; /* Set Bit0 to 1 */ |
789fc0adb [WATCHDOG] NS pc8... |
104 |
outb_p(0x30, WDT_INDEX_IO_PORT); |
7944d3a5a [WATCHDOG] more c... |
105 |
outb_p(cr_data, WDT_DATA_IO_PORT); /* Index0x30_bit0P1 */ |
789fc0adb [WATCHDOG] NS pc8... |
106 |
|
00b3b3e66 [WATCHDOG] NS pc8... |
107 |
#ifdef DEBUG |
27c766aaa watchdog: Use pr_... |
108 109 |
pr_info(DPFX "pc87413 - Enable SWC functions "); |
00b3b3e66 [WATCHDOG] NS pc8... |
110 |
#endif |
789fc0adb [WATCHDOG] NS pc8... |
111 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
112 |
/* Read SWC I/O base address */ |
7ccdb9467 watchdog: pc87413... |
113 |
static void pc87413_get_swc_base_addr(void) |
789fc0adb [WATCHDOG] NS pc8... |
114 |
{ |
00b3b3e66 [WATCHDOG] NS pc8... |
115 |
unsigned char addr_l, addr_h = 0; |
789fc0adb [WATCHDOG] NS pc8... |
116 117 |
/* Step 3: Read SWC I/O Base Address */ |
7944d3a5a [WATCHDOG] more c... |
118 |
outb_p(0x60, WDT_INDEX_IO_PORT); /* Read Index 0x60 */ |
00b3b3e66 [WATCHDOG] NS pc8... |
119 |
addr_h = inb(WDT_DATA_IO_PORT); |
789fc0adb [WATCHDOG] NS pc8... |
120 |
|
7944d3a5a [WATCHDOG] more c... |
121 |
outb_p(0x61, WDT_INDEX_IO_PORT); /* Read Index 0x61 */ |
789fc0adb [WATCHDOG] NS pc8... |
122 |
|
00b3b3e66 [WATCHDOG] NS pc8... |
123 |
addr_l = inb(WDT_DATA_IO_PORT); |
789fc0adb [WATCHDOG] NS pc8... |
124 125 |
swc_base_addr = (addr_h << 8) + addr_l; |
00b3b3e66 [WATCHDOG] NS pc8... |
126 |
#ifdef DEBUG |
27c766aaa watchdog: Use pr_... |
127 |
pr_info(DPFX |
aee334c23 [WATCHDOG 31/57] ... |
128 129 130 |
"Read SWC I/O Base Address: low %d, high %d, res %d ", addr_l, addr_h, swc_base_addr); |
00b3b3e66 [WATCHDOG] NS pc8... |
131 |
#endif |
789fc0adb [WATCHDOG] NS pc8... |
132 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
133 |
/* Select Bank 3 of SWC */ |
7ccdb9467 watchdog: pc87413... |
134 |
static inline void pc87413_swc_bank3(void) |
789fc0adb [WATCHDOG] NS pc8... |
135 136 |
{ /* Step 4: Select Bank3 of SWC */ |
00b3b3e66 [WATCHDOG] NS pc8... |
137 |
outb_p(inb(swc_base_addr + 0x0f) | 0x03, swc_base_addr + 0x0f); |
00b3b3e66 [WATCHDOG] NS pc8... |
138 |
#ifdef DEBUG |
27c766aaa watchdog: Use pr_... |
139 140 |
pr_info(DPFX "Select Bank3 of SWC "); |
00b3b3e66 [WATCHDOG] NS pc8... |
141 |
#endif |
789fc0adb [WATCHDOG] NS pc8... |
142 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
143 |
/* Set watchdog timeout to x minutes */ |
7ccdb9467 watchdog: pc87413... |
144 |
static inline void pc87413_programm_wdto(char pc87413_time) |
789fc0adb [WATCHDOG] NS pc8... |
145 146 |
{ /* Step 5: Programm WDTO, Twd. */ |
00b3b3e66 [WATCHDOG] NS pc8... |
147 |
outb_p(pc87413_time, swc_base_addr + WDTO); |
00b3b3e66 [WATCHDOG] NS pc8... |
148 |
#ifdef DEBUG |
27c766aaa watchdog: Use pr_... |
149 150 |
pr_info(DPFX "Set WDTO to %d minutes ", pc87413_time); |
00b3b3e66 [WATCHDOG] NS pc8... |
151 |
#endif |
789fc0adb [WATCHDOG] NS pc8... |
152 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
153 |
/* Enable WDEN */ |
7ccdb9467 watchdog: pc87413... |
154 |
static inline void pc87413_enable_wden(void) |
789fc0adb [WATCHDOG] NS pc8... |
155 156 |
{ /* Step 6: Enable WDEN */ |
aee334c23 [WATCHDOG 31/57] ... |
157 |
outb_p(inb(swc_base_addr + WDCTL) | 0x01, swc_base_addr + WDCTL); |
00b3b3e66 [WATCHDOG] NS pc8... |
158 |
#ifdef DEBUG |
27c766aaa watchdog: Use pr_... |
159 160 |
pr_info(DPFX "Enable WDEN "); |
00b3b3e66 [WATCHDOG] NS pc8... |
161 |
#endif |
789fc0adb [WATCHDOG] NS pc8... |
162 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
163 |
/* Enable SW_WD_TREN */ |
7ccdb9467 watchdog: pc87413... |
164 |
static inline void pc87413_enable_sw_wd_tren(void) |
789fc0adb [WATCHDOG] NS pc8... |
165 166 |
{ /* Enable SW_WD_TREN */ |
aee334c23 [WATCHDOG 31/57] ... |
167 |
outb_p(inb(swc_base_addr + WDCFG) | 0x80, swc_base_addr + WDCFG); |
00b3b3e66 [WATCHDOG] NS pc8... |
168 |
#ifdef DEBUG |
27c766aaa watchdog: Use pr_... |
169 170 |
pr_info(DPFX "Enable SW_WD_TREN "); |
00b3b3e66 [WATCHDOG] NS pc8... |
171 |
#endif |
789fc0adb [WATCHDOG] NS pc8... |
172 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
173 |
/* Disable SW_WD_TREN */ |
7ccdb9467 watchdog: pc87413... |
174 |
static inline void pc87413_disable_sw_wd_tren(void) |
789fc0adb [WATCHDOG] NS pc8... |
175 176 |
{ /* Disable SW_WD_TREN */ |
aee334c23 [WATCHDOG 31/57] ... |
177 |
outb_p(inb(swc_base_addr + WDCFG) & 0x7f, swc_base_addr + WDCFG); |
00b3b3e66 [WATCHDOG] NS pc8... |
178 |
#ifdef DEBUG |
27c766aaa watchdog: Use pr_... |
179 180 |
pr_info(DPFX "pc87413 - Disable SW_WD_TREN "); |
00b3b3e66 [WATCHDOG] NS pc8... |
181 |
#endif |
789fc0adb [WATCHDOG] NS pc8... |
182 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
183 |
/* Enable SW_WD_TRG */ |
789fc0adb [WATCHDOG] NS pc8... |
184 |
|
7ccdb9467 watchdog: pc87413... |
185 |
static inline void pc87413_enable_sw_wd_trg(void) |
789fc0adb [WATCHDOG] NS pc8... |
186 |
{ |
789fc0adb [WATCHDOG] NS pc8... |
187 |
/* Enable SW_WD_TRG */ |
aee334c23 [WATCHDOG 31/57] ... |
188 |
outb_p(inb(swc_base_addr + WDCTL) | 0x80, swc_base_addr + WDCTL); |
00b3b3e66 [WATCHDOG] NS pc8... |
189 |
#ifdef DEBUG |
27c766aaa watchdog: Use pr_... |
190 191 |
pr_info(DPFX "pc87413 - Enable SW_WD_TRG "); |
00b3b3e66 [WATCHDOG] NS pc8... |
192 |
#endif |
789fc0adb [WATCHDOG] NS pc8... |
193 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
194 |
/* Disable SW_WD_TRG */ |
789fc0adb [WATCHDOG] NS pc8... |
195 |
|
7ccdb9467 watchdog: pc87413... |
196 |
static inline void pc87413_disable_sw_wd_trg(void) |
00b3b3e66 [WATCHDOG] NS pc8... |
197 |
{ |
789fc0adb [WATCHDOG] NS pc8... |
198 |
/* Disable SW_WD_TRG */ |
aee334c23 [WATCHDOG 31/57] ... |
199 |
outb_p(inb(swc_base_addr + WDCTL) & 0x7f, swc_base_addr + WDCTL); |
00b3b3e66 [WATCHDOG] NS pc8... |
200 |
#ifdef DEBUG |
27c766aaa watchdog: Use pr_... |
201 202 |
pr_info(DPFX "Disable SW_WD_TRG "); |
00b3b3e66 [WATCHDOG] NS pc8... |
203 |
#endif |
789fc0adb [WATCHDOG] NS pc8... |
204 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
205 |
/* -- Higher level functions ------------------------------------*/ |
789fc0adb [WATCHDOG] NS pc8... |
206 |
|
00b3b3e66 [WATCHDOG] NS pc8... |
207 |
/* Enable the watchdog */ |
789fc0adb [WATCHDOG] NS pc8... |
208 |
|
00b3b3e66 [WATCHDOG] NS pc8... |
209 |
static void pc87413_enable(void) |
789fc0adb [WATCHDOG] NS pc8... |
210 |
{ |
00b3b3e66 [WATCHDOG] NS pc8... |
211 |
spin_lock(&io_lock); |
789fc0adb [WATCHDOG] NS pc8... |
212 |
|
7ccdb9467 watchdog: pc87413... |
213 214 215 216 217 |
pc87413_swc_bank3(); pc87413_programm_wdto(timeout); pc87413_enable_wden(); pc87413_enable_sw_wd_tren(); pc87413_enable_sw_wd_trg(); |
00b3b3e66 [WATCHDOG] NS pc8... |
218 219 |
spin_unlock(&io_lock); |
789fc0adb [WATCHDOG] NS pc8... |
220 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
221 |
/* Disable the watchdog */ |
789fc0adb [WATCHDOG] NS pc8... |
222 |
|
00b3b3e66 [WATCHDOG] NS pc8... |
223 |
static void pc87413_disable(void) |
789fc0adb [WATCHDOG] NS pc8... |
224 |
{ |
00b3b3e66 [WATCHDOG] NS pc8... |
225 |
spin_lock(&io_lock); |
789fc0adb [WATCHDOG] NS pc8... |
226 |
|
7ccdb9467 watchdog: pc87413... |
227 228 229 230 |
pc87413_swc_bank3(); pc87413_disable_sw_wd_tren(); pc87413_disable_sw_wd_trg(); pc87413_programm_wdto(0); |
00b3b3e66 [WATCHDOG] NS pc8... |
231 232 |
spin_unlock(&io_lock); |
789fc0adb [WATCHDOG] NS pc8... |
233 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
234 |
/* Refresh the watchdog */ |
789fc0adb [WATCHDOG] NS pc8... |
235 |
|
00b3b3e66 [WATCHDOG] NS pc8... |
236 |
static void pc87413_refresh(void) |
789fc0adb [WATCHDOG] NS pc8... |
237 |
{ |
00b3b3e66 [WATCHDOG] NS pc8... |
238 |
spin_lock(&io_lock); |
789fc0adb [WATCHDOG] NS pc8... |
239 |
|
7ccdb9467 watchdog: pc87413... |
240 241 242 243 244 245 246 |
pc87413_swc_bank3(); pc87413_disable_sw_wd_tren(); pc87413_disable_sw_wd_trg(); pc87413_programm_wdto(timeout); pc87413_enable_wden(); pc87413_enable_sw_wd_tren(); pc87413_enable_sw_wd_trg(); |
789fc0adb [WATCHDOG] NS pc8... |
247 |
|
00b3b3e66 [WATCHDOG] NS pc8... |
248 |
spin_unlock(&io_lock); |
789fc0adb [WATCHDOG] NS pc8... |
249 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
/* -- File operations -------------------------------------------*/ /** * pc87413_open: * @inode: inode of device * @file: file handle to device * */ static int pc87413_open(struct inode *inode, struct file *file) { /* /dev/watchdog can only be opened once */ if (test_and_set_bit(0, &timer_enabled)) return -EBUSY; if (nowayout) __module_get(THIS_MODULE); |
789fc0adb [WATCHDOG] NS pc8... |
268 |
|
00b3b3e66 [WATCHDOG] NS pc8... |
269 270 |
/* Reload and activate timer */ pc87413_refresh(); |
789fc0adb [WATCHDOG] NS pc8... |
271 |
|
27c766aaa watchdog: Use pr_... |
272 273 |
pr_info("Watchdog enabled. Timeout set to %d minute(s). ", timeout); |
00b3b3e66 [WATCHDOG] NS pc8... |
274 275 276 |
return nonseekable_open(inode, file); } |
789fc0adb [WATCHDOG] NS pc8... |
277 278 |
/** |
00b3b3e66 [WATCHDOG] NS pc8... |
279 280 281 |
* pc87413_release: * @inode: inode to board * @file: file handle to board |
789fc0adb [WATCHDOG] NS pc8... |
282 |
* |
00b3b3e66 [WATCHDOG] NS pc8... |
283 284 285 286 287 |
* The watchdog has a configurable API. There is a religious dispute * between people who want their watchdog to be able to shut down and * those who want to be sure if the watchdog manager dies the machine * reboots. In the former case we disable the counters, in the latter * case you have to open it again very soon. |
789fc0adb [WATCHDOG] NS pc8... |
288 |
*/ |
00b3b3e66 [WATCHDOG] NS pc8... |
289 |
static int pc87413_release(struct inode *inode, struct file *file) |
789fc0adb [WATCHDOG] NS pc8... |
290 |
{ |
00b3b3e66 [WATCHDOG] NS pc8... |
291 292 293 294 |
/* Shut off the timer. */ if (expect_close == 42) { pc87413_disable(); |
27c766aaa watchdog: Use pr_... |
295 296 |
pr_info("Watchdog disabled, sleeping again... "); |
00b3b3e66 [WATCHDOG] NS pc8... |
297 |
} else { |
27c766aaa watchdog: Use pr_... |
298 299 |
pr_crit("Unexpected close, not stopping watchdog! "); |
00b3b3e66 [WATCHDOG] NS pc8... |
300 301 |
pc87413_refresh(); } |
00b3b3e66 [WATCHDOG] NS pc8... |
302 303 |
clear_bit(0, &timer_enabled); expect_close = 0; |
00b3b3e66 [WATCHDOG] NS pc8... |
304 |
return 0; |
789fc0adb [WATCHDOG] NS pc8... |
305 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
306 307 308 309 310 311 312 313 |
/** * pc87413_status: * * return, if the watchdog is enabled (timeout is set...) */ static int pc87413_status(void) |
789fc0adb [WATCHDOG] NS pc8... |
314 |
{ |
0835caa2b [WATCHDOG] NS pc8... |
315 |
return 0; /* currently not supported */ |
789fc0adb [WATCHDOG] NS pc8... |
316 317 318 319 320 |
} /** * pc87413_write: * @file: file handle to the watchdog |
00b3b3e66 [WATCHDOG] NS pc8... |
321 322 |
* @data: data buffer to write * @len: length in bytes |
789fc0adb [WATCHDOG] NS pc8... |
323 324 325 326 327 |
* @ppos: pointer to the position to write. No seeks allowed * * A write to a watchdog device is defined as a keepalive signal. Any * write of data will do, as we we don't define content meaning. */ |
00b3b3e66 [WATCHDOG] NS pc8... |
328 329 |
static ssize_t pc87413_write(struct file *file, const char __user *data, size_t len, loff_t *ppos) |
789fc0adb [WATCHDOG] NS pc8... |
330 |
{ |
00b3b3e66 [WATCHDOG] NS pc8... |
331 332 333 334 335 336 337 |
/* See if we got the magic character 'V' and reload the timer */ if (len) { if (!nowayout) { size_t i; /* reset expect flag */ expect_close = 0; |
aee334c23 [WATCHDOG 31/57] ... |
338 339 |
/* scan to see whether or not we got the magic character */ |
00b3b3e66 [WATCHDOG] NS pc8... |
340 341 |
for (i = 0; i != len; i++) { char c; |
7944d3a5a [WATCHDOG] more c... |
342 |
if (get_user(c, data + i)) |
00b3b3e66 [WATCHDOG] NS pc8... |
343 344 345 346 347 348 349 350 |
return -EFAULT; if (c == 'V') expect_close = 42; } } /* someone wrote to us, we should reload the timer */ pc87413_refresh(); |
789fc0adb [WATCHDOG] NS pc8... |
351 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
352 |
return len; |
789fc0adb [WATCHDOG] NS pc8... |
353 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
354 |
/** |
789fc0adb [WATCHDOG] NS pc8... |
355 |
* pc87413_ioctl: |
789fc0adb [WATCHDOG] NS pc8... |
356 357 358 359 360 361 362 363 |
* @file: file handle to the device * @cmd: watchdog command * @arg: argument pointer * * The watchdog API defines a common set of functions for all watchdogs * according to their available features. We only actually usefully support * querying capabilities and current status. */ |
aee334c23 [WATCHDOG 31/57] ... |
364 365 |
static long pc87413_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
789fc0adb [WATCHDOG] NS pc8... |
366 |
{ |
00b3b3e66 [WATCHDOG] NS pc8... |
367 368 369 370 371 372 |
int new_timeout; union { struct watchdog_info __user *ident; int __user *i; } uarg; |
42747d712 [WATCHDOG] watchd... |
373 |
static const struct watchdog_info ident = { |
00b3b3e66 [WATCHDOG] NS pc8... |
374 |
.options = WDIOF_KEEPALIVEPING | |
aee334c23 [WATCHDOG 31/57] ... |
375 376 |
WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, |
00b3b3e66 [WATCHDOG] NS pc8... |
377 |
.firmware_version = 1, |
7944d3a5a [WATCHDOG] more c... |
378 |
.identity = "PC87413(HF/F) watchdog", |
789fc0adb [WATCHDOG] NS pc8... |
379 |
}; |
00b3b3e66 [WATCHDOG] NS pc8... |
380 |
uarg.i = (int __user *)arg; |
789fc0adb [WATCHDOG] NS pc8... |
381 |
|
aee334c23 [WATCHDOG 31/57] ... |
382 383 384 385 386 387 388 389 |
switch (cmd) { case WDIOC_GETSUPPORT: return copy_to_user(uarg.ident, &ident, sizeof(ident)) ? -EFAULT : 0; case WDIOC_GETSTATUS: return put_user(pc87413_status(), uarg.i); case WDIOC_GETBOOTSTATUS: return put_user(0, uarg.i); |
0c06090c9 [WATCHDOG] Coding... |
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
case WDIOC_SETOPTIONS: { int options, retval = -EINVAL; if (get_user(options, uarg.i)) return -EFAULT; if (options & WDIOS_DISABLECARD) { pc87413_disable(); retval = 0; } if (options & WDIOS_ENABLECARD) { pc87413_enable(); retval = 0; } return retval; } |
aee334c23 [WATCHDOG 31/57] ... |
405 406 |
case WDIOC_KEEPALIVE: pc87413_refresh(); |
00b3b3e66 [WATCHDOG] NS pc8... |
407 |
#ifdef DEBUG |
27c766aaa watchdog: Use pr_... |
408 409 |
pr_info(DPFX "keepalive "); |
00b3b3e66 [WATCHDOG] NS pc8... |
410 |
#endif |
aee334c23 [WATCHDOG 31/57] ... |
411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
return 0; case WDIOC_SETTIMEOUT: if (get_user(new_timeout, uarg.i)) return -EFAULT; /* the API states this is given in secs */ new_timeout /= 60; if (new_timeout < 0 || new_timeout > MAX_TIMEOUT) return -EINVAL; timeout = new_timeout; pc87413_refresh(); /* fall through and return the new timeout... */ case WDIOC_GETTIMEOUT: new_timeout = timeout * 60; return put_user(new_timeout, uarg.i); |
aee334c23 [WATCHDOG 31/57] ... |
425 426 |
default: return -ENOTTY; |
789fc0adb [WATCHDOG] NS pc8... |
427 |
} |
789fc0adb [WATCHDOG] NS pc8... |
428 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
429 |
/* -- Notifier funtions -----------------------------------------*/ |
789fc0adb [WATCHDOG] NS pc8... |
430 431 432 433 434 435 436 437 438 439 440 |
/** * notify_sys: * @this: our notifier block * @code: the event being reported * @unused: unused * * Our notifier is called on system shutdowns. We want to turn the card * off at reboot otherwise the machine will reboot again during memory * test or worse yet during the following fsck. This would suck, in fact * trust me - if it happens it does suck. */ |
00b3b3e66 [WATCHDOG] NS pc8... |
441 442 443 |
static int pc87413_notify_sys(struct notifier_block *this, unsigned long code, void *unused) |
789fc0adb [WATCHDOG] NS pc8... |
444 |
{ |
00b3b3e66 [WATCHDOG] NS pc8... |
445 |
if (code == SYS_DOWN || code == SYS_HALT) |
789fc0adb [WATCHDOG] NS pc8... |
446 447 |
/* Turn the card off */ pc87413_disable(); |
789fc0adb [WATCHDOG] NS pc8... |
448 449 |
return NOTIFY_DONE; } |
00b3b3e66 [WATCHDOG] NS pc8... |
450 |
/* -- Module's structures ---------------------------------------*/ |
789fc0adb [WATCHDOG] NS pc8... |
451 |
|
2b8693c06 [PATCH] mark stru... |
452 |
static const struct file_operations pc87413_fops = { |
789fc0adb [WATCHDOG] NS pc8... |
453 |
.owner = THIS_MODULE, |
00b3b3e66 [WATCHDOG] NS pc8... |
454 |
.llseek = no_llseek, |
789fc0adb [WATCHDOG] NS pc8... |
455 |
.write = pc87413_write, |
aee334c23 [WATCHDOG 31/57] ... |
456 |
.unlocked_ioctl = pc87413_ioctl, |
789fc0adb [WATCHDOG] NS pc8... |
457 458 459 |
.open = pc87413_open, .release = pc87413_release, }; |
aee334c23 [WATCHDOG 31/57] ... |
460 |
static struct notifier_block pc87413_notifier = { |
00b3b3e66 [WATCHDOG] NS pc8... |
461 |
.notifier_call = pc87413_notify_sys, |
789fc0adb [WATCHDOG] NS pc8... |
462 |
}; |
aee334c23 [WATCHDOG 31/57] ... |
463 |
static struct miscdevice pc87413_miscdev = { |
00b3b3e66 [WATCHDOG] NS pc8... |
464 465 |
.minor = WATCHDOG_MINOR, .name = "watchdog", |
7944d3a5a [WATCHDOG] more c... |
466 |
.fops = &pc87413_fops, |
789fc0adb [WATCHDOG] NS pc8... |
467 |
}; |
00b3b3e66 [WATCHDOG] NS pc8... |
468 |
/* -- Module init functions -------------------------------------*/ |
789fc0adb [WATCHDOG] NS pc8... |
469 470 |
/** |
5f3b27569 watchdog: cleanup... |
471 |
* pc87413_init: module's "constructor" |
789fc0adb [WATCHDOG] NS pc8... |
472 473 474 475 476 |
* * Set up the WDT watchdog board. All we have to do is grab the * resources we require and bitch if anyone beat us to them. * The open() function will actually kick the board off. */ |
00b3b3e66 [WATCHDOG] NS pc8... |
477 |
static int __init pc87413_init(void) |
789fc0adb [WATCHDOG] NS pc8... |
478 479 |
{ int ret; |
27c766aaa watchdog: Use pr_... |
480 481 |
pr_info("Version " VERSION " at io 0x%X ", |
aee334c23 [WATCHDOG 31/57] ... |
482 |
WDT_INDEX_IO_PORT); |
789fc0adb [WATCHDOG] NS pc8... |
483 |
|
7ccdb9467 watchdog: pc87413... |
484 485 |
if (!request_muxed_region(io, 2, MODNAME)) return -EBUSY; |
789fc0adb [WATCHDOG] NS pc8... |
486 |
|
789fc0adb [WATCHDOG] NS pc8... |
487 |
ret = register_reboot_notifier(&pc87413_notifier); |
5f5e19093 watchdog: fix che... |
488 |
if (ret != 0) |
27c766aaa watchdog: Use pr_... |
489 490 |
pr_err("cannot register reboot notifier (err=%d) ", ret); |
789fc0adb [WATCHDOG] NS pc8... |
491 |
|
789fc0adb [WATCHDOG] NS pc8... |
492 |
ret = misc_register(&pc87413_miscdev); |
789fc0adb [WATCHDOG] NS pc8... |
493 |
if (ret != 0) { |
27c766aaa watchdog: Use pr_... |
494 495 496 |
pr_err("cannot register miscdev on minor=%d (err=%d) ", WATCHDOG_MINOR, ret); |
7ccdb9467 watchdog: pc87413... |
497 |
goto reboot_unreg; |
789fc0adb [WATCHDOG] NS pc8... |
498 |
} |
27c766aaa watchdog: Use pr_... |
499 500 |
pr_info("initialized. timeout=%d min ", timeout); |
7ccdb9467 watchdog: pc87413... |
501 502 503 504 505 506 |
pc87413_select_wdt_out(); pc87413_enable_swc(); pc87413_get_swc_base_addr(); if (!request_region(swc_base_addr, 0x20, MODNAME)) { |
27c766aaa watchdog: Use pr_... |
507 508 |
pr_err("cannot request SWC region at 0x%x ", swc_base_addr); |
7ccdb9467 watchdog: pc87413... |
509 510 511 |
ret = -EBUSY; goto misc_unreg; } |
00b3b3e66 [WATCHDOG] NS pc8... |
512 |
pc87413_enable(); |
7ccdb9467 watchdog: pc87413... |
513 514 |
release_region(io, 2); |
789fc0adb [WATCHDOG] NS pc8... |
515 |
return 0; |
7ccdb9467 watchdog: pc87413... |
516 517 518 519 520 521 522 |
misc_unreg: misc_deregister(&pc87413_miscdev); reboot_unreg: unregister_reboot_notifier(&pc87413_notifier); release_region(io, 2); return ret; |
789fc0adb [WATCHDOG] NS pc8... |
523 |
} |
00b3b3e66 [WATCHDOG] NS pc8... |
524 525 526 527 528 529 530 531 532 533 534 535 536 |
/** * pc87413_exit: module's "destructor" * * Unload the watchdog. You cannot do this with any file handles open. * If your watchdog is set to continue ticking on close and you unload * it, well it keeps ticking. We won't get the interrupt but the board * will not touch PC memory so all is fine. You just have to load a new * module in 60 seconds or reboot. */ static void __exit pc87413_exit(void) { /* Stop the timer before we leave */ |
aee334c23 [WATCHDOG 31/57] ... |
537 |
if (!nowayout) { |
00b3b3e66 [WATCHDOG] NS pc8... |
538 |
pc87413_disable(); |
27c766aaa watchdog: Use pr_... |
539 540 |
pr_info("Watchdog disabled "); |
00b3b3e66 [WATCHDOG] NS pc8... |
541 542 543 544 |
} misc_deregister(&pc87413_miscdev); unregister_reboot_notifier(&pc87413_notifier); |
7ccdb9467 watchdog: pc87413... |
545 |
release_region(swc_base_addr, 0x20); |
00b3b3e66 [WATCHDOG] NS pc8... |
546 |
|
27c766aaa watchdog: Use pr_... |
547 548 |
pr_info("watchdog component driver removed "); |
00b3b3e66 [WATCHDOG] NS pc8... |
549 |
} |
789fc0adb [WATCHDOG] NS pc8... |
550 551 552 |
module_init(pc87413_init); module_exit(pc87413_exit); |
5f5e19093 watchdog: fix che... |
553 554 |
MODULE_AUTHOR("Sven Anders <anders@anduras.de>"); MODULE_AUTHOR("Marcus Junker <junker@anduras.de>"); |
789fc0adb [WATCHDOG] NS pc8... |
555 |
MODULE_DESCRIPTION("PC87413 WDT driver"); |
00b3b3e66 [WATCHDOG] NS pc8... |
556 |
MODULE_LICENSE("GPL"); |
00b3b3e66 [WATCHDOG] NS pc8... |
557 |
module_param(io, int, 0); |
76550d329 watchdog: fix sev... |
558 559 |
MODULE_PARM_DESC(io, MODNAME " I/O port (default: " __MODULE_STRING(IO_DEFAULT) ")."); |
00b3b3e66 [WATCHDOG] NS pc8... |
560 561 |
module_param(timeout, int, 0); |
aee334c23 [WATCHDOG 31/57] ... |
562 563 |
MODULE_PARM_DESC(timeout, "Watchdog timeout in minutes (default=" |
76550d329 watchdog: fix sev... |
564 |
__MODULE_STRING(DEFAULT_TIMEOUT) ")."); |
00b3b3e66 [WATCHDOG] NS pc8... |
565 |
|
86a1e1896 watchdog: nowayou... |
566 |
module_param(nowayout, bool, 0); |
aee334c23 [WATCHDOG 31/57] ... |
567 568 569 |
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
00b3b3e66 [WATCHDOG] NS pc8... |
570 |