summaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorMoritz Fischer <mdf@kernel.org>2017-04-24 18:05:11 -0400
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>2017-05-04 08:45:25 -0400
commit453d0744f6c6ca3f9749b8c57c2e85b5b9f52514 (patch)
tree7b0e1ba9e522b06f925638beb731e6d411b9ef03 /drivers/rtc
parent5d05e81516cfe7606ee0cd8278fe225314dccfbe (diff)
rtc: ds1374: wdt: Fix issue with timeout scaling from secs to wdt ticks
The issue is that the internal counter that triggers the watchdog reset is actually running at 4096 Hz instead of 1Hz, therefore the value given by userland (in sec) needs to be multiplied by 4096 to get the correct behavior. Fixes: 920f91e50c5b ("drivers/rtc/rtc-ds1374.c: add watchdog support") Signed-off-by: Moritz Fischer <mdf@kernel.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-ds1374.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c
index 4cd115e93223..2a8b5b3e429b 100644
--- a/drivers/rtc/rtc-ds1374.c
+++ b/drivers/rtc/rtc-ds1374.c
@@ -525,6 +525,10 @@ static long ds1374_wdt_ioctl(struct file *file, unsigned int cmd,
525 if (get_user(new_margin, (int __user *)arg)) 525 if (get_user(new_margin, (int __user *)arg))
526 return -EFAULT; 526 return -EFAULT;
527 527
528 /* the hardware's tick rate is 4096 Hz, so
529 * the counter value needs to be scaled accordingly
530 */
531 new_margin <<= 12;
528 if (new_margin < 1 || new_margin > 16777216) 532 if (new_margin < 1 || new_margin > 16777216)
529 return -EINVAL; 533 return -EINVAL;
530 534
@@ -533,7 +537,8 @@ static long ds1374_wdt_ioctl(struct file *file, unsigned int cmd,
533 ds1374_wdt_ping(); 537 ds1374_wdt_ping();
534 /* fallthrough */ 538 /* fallthrough */
535 case WDIOC_GETTIMEOUT: 539 case WDIOC_GETTIMEOUT:
536 return put_user(wdt_margin, (int __user *)arg); 540 /* when returning ... inverse is true */
541 return put_user((wdt_margin >> 12), (int __user *)arg);
537 case WDIOC_SETOPTIONS: 542 case WDIOC_SETOPTIONS:
538 if (copy_from_user(&options, (int __user *)arg, sizeof(int))) 543 if (copy_from_user(&options, (int __user *)arg, sizeof(int)))
539 return -EFAULT; 544 return -EFAULT;