]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
rtc: ds1374: wdt: Fix issue with timeout scaling from secs to wdt ticks
authorMoritz Fischer <mdf@kernel.org>
Mon, 24 Apr 2017 22:05:11 +0000 (15:05 -0700)
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>
Thu, 4 May 2017 12:45:25 +0000 (14:45 +0200)
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>
drivers/rtc/rtc-ds1374.c

index 4cd115e93223b4aea3b9a05f4a9df4b9c48a646e..2a8b5b3e429bcf96ae77357014c2055a936a2de0 100644 (file)
@@ -525,6 +525,10 @@ static long ds1374_wdt_ioctl(struct file *file, unsigned int cmd,
                if (get_user(new_margin, (int __user *)arg))
                        return -EFAULT;
 
+               /* the hardware's tick rate is 4096 Hz, so
+                * the counter value needs to be scaled accordingly
+                */
+               new_margin <<= 12;
                if (new_margin < 1 || new_margin > 16777216)
                        return -EINVAL;
 
@@ -533,7 +537,8 @@ static long ds1374_wdt_ioctl(struct file *file, unsigned int cmd,
                ds1374_wdt_ping();
                /* fallthrough */
        case WDIOC_GETTIMEOUT:
-               return put_user(wdt_margin, (int __user *)arg);
+               /* when returning ... inverse is true */
+               return put_user((wdt_margin >> 12), (int __user *)arg);
        case WDIOC_SETOPTIONS:
                if (copy_from_user(&options, (int __user *)arg, sizeof(int)))
                        return -EFAULT;