Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Greg Lee and committed by
Wim Van Sebroeck
c63b6d02 86b59128

+27 -6
+27 -6
drivers/watchdog/w83627hf_wdt.c
··· 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 ··· 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 ··· 174 174 return -EINVAL; 175 175 timeout = t; 176 176 return 0; 177 + } 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; 177 195 } 178 196 179 197 static ssize_t wdt_write(struct file *file, const char __user *buf, ··· 220 202 { 221 203 void __user *argp = (void __user *)arg; 222 204 int __user *p = argp; 223 - int new_timeout; 205 + int timeval; 224 206 static const struct watchdog_info ident = { 225 207 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | 226 208 WDIOF_MAGICCLOSE, ··· 256 238 wdt_ping(); 257 239 break; 258 240 case WDIOC_SETTIMEOUT: 259 - if (get_user(new_timeout, p)) 241 + if (get_user(timeval, p)) 260 242 return -EFAULT; 261 - if (wdt_set_heartbeat(new_timeout)) 243 + if (wdt_set_heartbeat(timeval)) 262 244 return -EINVAL; 263 245 wdt_ping(); 264 246 /* Fall */ 265 247 case WDIOC_GETTIMEOUT: 266 248 return put_user(timeout, p); 249 + case WDIOC_GETTIMELEFT: 250 + timeval = wdt_get_time(); 251 + return put_user(timeval, p); 267 252 default: 268 253 return -ENOTTY; 269 254 }