Commit c63b6d02be22899a5c8d47b8ee40e0534cd01a43
Committed by
Wim Van Sebroeck
1 parent
86b5912880
Exists in
master
and in
38 other branches
watchdog: Add WDIOC_GETTIMELEFT ioctl support to w83627 watchdog driver
Add WDIOC_GETTIMELEFT ioctl allowing you to check how much time is left on the watchdog counter before a reset occurs. Signed-off-by: Greg Lee <glee [at] swspec.com> Signed-off-by: Padraig Brady <P@draigbrady.com> Signed-off-by: Wim Van Sebroeck <wim@iguana.be> Signed-off-by: Andrew Morton <akpm@google.com>
Showing 1 changed file with 27 additions and 6 deletions Side-by-side Diff
drivers/watchdog/w83627hf_wdt.c
... | ... | @@ -142,7 +142,7 @@ |
142 | 142 | w83627hf_unselect_wd_register(); |
143 | 143 | } |
144 | 144 | |
145 | -static void wdt_ctrl(int timeout) | |
145 | +static void wdt_set_time(int timeout) | |
146 | 146 | { |
147 | 147 | spin_lock(&io_lock); |
148 | 148 | |
149 | 149 | |
... | ... | @@ -158,13 +158,13 @@ |
158 | 158 | |
159 | 159 | static int wdt_ping(void) |
160 | 160 | { |
161 | - wdt_ctrl(timeout); | |
161 | + wdt_set_time(timeout); | |
162 | 162 | return 0; |
163 | 163 | } |
164 | 164 | |
165 | 165 | static int wdt_disable(void) |
166 | 166 | { |
167 | - wdt_ctrl(0); | |
167 | + wdt_set_time(0); | |
168 | 168 | return 0; |
169 | 169 | } |
170 | 170 | |
... | ... | @@ -176,6 +176,24 @@ |
176 | 176 | return 0; |
177 | 177 | } |
178 | 178 | |
179 | +static int wdt_get_time(void) | |
180 | +{ | |
181 | + int timeleft; | |
182 | + | |
183 | + spin_lock(&io_lock); | |
184 | + | |
185 | + w83627hf_select_wd_register(); | |
186 | + | |
187 | + outb_p(0xF6, WDT_EFER); /* Select CRF6 */ | |
188 | + timeleft = inb_p(WDT_EFDR); /* Read Timeout counter to CRF6 */ | |
189 | + | |
190 | + w83627hf_unselect_wd_register(); | |
191 | + | |
192 | + spin_unlock(&io_lock); | |
193 | + | |
194 | + return timeleft; | |
195 | +} | |
196 | + | |
179 | 197 | static ssize_t wdt_write(struct file *file, const char __user *buf, |
180 | 198 | size_t count, loff_t *ppos) |
181 | 199 | { |
... | ... | @@ -202,7 +220,7 @@ |
202 | 220 | { |
203 | 221 | void __user *argp = (void __user *)arg; |
204 | 222 | int __user *p = argp; |
205 | - int new_timeout; | |
223 | + int timeval; | |
206 | 224 | static const struct watchdog_info ident = { |
207 | 225 | .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | |
208 | 226 | WDIOF_MAGICCLOSE, |
209 | 227 | |
210 | 228 | |
... | ... | @@ -238,14 +256,17 @@ |
238 | 256 | wdt_ping(); |
239 | 257 | break; |
240 | 258 | case WDIOC_SETTIMEOUT: |
241 | - if (get_user(new_timeout, p)) | |
259 | + if (get_user(timeval, p)) | |
242 | 260 | return -EFAULT; |
243 | - if (wdt_set_heartbeat(new_timeout)) | |
261 | + if (wdt_set_heartbeat(timeval)) | |
244 | 262 | return -EINVAL; |
245 | 263 | wdt_ping(); |
246 | 264 | /* Fall */ |
247 | 265 | case WDIOC_GETTIMEOUT: |
248 | 266 | return put_user(timeout, p); |
267 | + case WDIOC_GETTIMELEFT: | |
268 | + timeval = wdt_get_time(); | |
269 | + return put_user(timeval, p); | |
249 | 270 | default: |
250 | 271 | return -ENOTTY; |
251 | 272 | } |