Skip to content

Commit c63b6d0

Browse files
gleehokieWim Van Sebroeck
authored andcommitted
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>
1 parent 86b5912 commit c63b6d0

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

‎drivers/watchdog/w83627hf_wdt.c‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static void w83627hf_init(void)
142142
w83627hf_unselect_wd_register();
143143
}
144144

145-
static void wdt_ctrl(int timeout)
145+
static void wdt_set_time(int timeout)
146146
{
147147
spin_lock(&io_lock);
148148

@@ -158,13 +158,13 @@ static void wdt_ctrl(int timeout)
158158

159159
static int wdt_ping(void)
160160
{
161-
wdt_ctrl(timeout);
161+
wdt_set_time(timeout);
162162
return 0;
163163
}
164164

165165
static int wdt_disable(void)
166166
{
167-
wdt_ctrl(0);
167+
wdt_set_time(0);
168168
return 0;
169169
}
170170

@@ -176,6 +176,24 @@ static int wdt_set_heartbeat(int t)
176176
return 0;
177177
}
178178

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+
179197
static ssize_t wdt_write(struct file *file, const char __user *buf,
180198
size_t count, loff_t *ppos)
181199
{
@@ -202,7 +220,7 @@ static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
202220
{
203221
void __user *argp = (void __user *)arg;
204222
int __user *p = argp;
205-
int new_timeout;
223+
int timeval;
206224
static const struct watchdog_info ident = {
207225
.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
208226
WDIOF_MAGICCLOSE,
@@ -238,14 +256,17 @@ static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
238256
wdt_ping();
239257
break;
240258
case WDIOC_SETTIMEOUT:
241-
if (get_user(new_timeout, p))
259+
if (get_user(timeval, p))
242260
return -EFAULT;
243-
if (wdt_set_heartbeat(new_timeout))
261+
if (wdt_set_heartbeat(timeval))
244262
return -EINVAL;
245263
wdt_ping();
246264
/* Fall */
247265
case WDIOC_GETTIMEOUT:
248266
return put_user(timeout, p);
267+
case WDIOC_GETTIMELEFT:
268+
timeval = wdt_get_time();
269+
return put_user(timeval, p);
249270
default:
250271
return -ENOTTY;
251272
}

0 commit comments

Comments
 (0)