All of lore.kernel.org
 help / color / mirror / Atom feed
From: Moritz Fischer <mdf@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: moritz.fischer@ettus.com, linux-watchdog@vger.kernel.org,
	linux@roeck-us.net, wim@iguana.be, a.zummo@towertech.it,
	alexandre.belloni@free-electrons.com, rtc-linux@googlegroups.com,
	alex.williams@ni.com, Moritz Fischer <mdf@kernel.org>
Subject: [PATCH 1/2] rtc: ds1374: wdt: Fix issue with timeout scaling from secs to wdt ticks
Date: Mon, 24 Apr 2017 15:05:11 -0700	[thread overview]
Message-ID: <1493071512-5718-2-git-send-email-mdf@kernel.org> (raw)
In-Reply-To: <1493071512-5718-1-git-send-email-mdf@kernel.org>

Fix commit 920f91e50c5b ("drivers/rtc/rtc-ds1374.c: add watchdog support")

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.

Signed-off-by: Moritz Fischer <mdf@kernel.org>
---
 drivers/rtc/rtc-ds1374.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c
index 4cd115e..2a8b5b3 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,
 		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;
-- 
2.7.4

WARNING: multiple messages have this Message-ID (diff)
From: Moritz Fischer <mdf@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: moritz.fischer@ettus.com, linux-watchdog@vger.kernel.org,
	linux@roeck-us.net, wim@iguana.be, a.zummo@towertech.it,
	alexandre.belloni@free-electrons.com, rtc-linux@googlegroups.com,
	alex.williams@ni.com, Moritz Fischer <mdf@kernel.org>
Subject: [rtc-linux] [PATCH 1/2] rtc: ds1374: wdt: Fix issue with timeout scaling from secs to wdt ticks
Date: Mon, 24 Apr 2017 15:05:11 -0700	[thread overview]
Message-ID: <1493071512-5718-2-git-send-email-mdf@kernel.org> (raw)
In-Reply-To: <1493071512-5718-1-git-send-email-mdf@kernel.org>

Fix commit 920f91e50c5b ("drivers/rtc/rtc-ds1374.c: add watchdog support")

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.

Signed-off-by: Moritz Fischer <mdf@kernel.org>
---
 drivers/rtc/rtc-ds1374.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c
index 4cd115e..2a8b5b3 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,
 		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;
-- 
2.7.4

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  reply	other threads:[~2017-04-24 22:06 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-24 22:05 [PATCH 0/2] DS1374 Watchdog fixes Moritz Fischer
2017-04-24 22:05 ` [rtc-linux] " Moritz Fischer
2017-04-24 22:05 ` Moritz Fischer [this message]
2017-04-24 22:05   ` [rtc-linux] [PATCH 1/2] rtc: ds1374: wdt: Fix issue with timeout scaling from secs to wdt ticks Moritz Fischer
2017-05-04 12:47   ` Alexandre Belloni
2017-05-04 12:47     ` [rtc-linux] " Alexandre Belloni
2017-04-24 22:05 ` [PATCH 2/2] rtc: ds1374: wdt: Fix stop/start ioctl always returning -EINVAL Moritz Fischer
2017-04-24 22:05   ` [rtc-linux] " Moritz Fischer
2017-05-04 12:47   ` Alexandre Belloni
2017-05-04 12:47     ` [rtc-linux] " Alexandre Belloni
2017-04-25  5:03 ` [PATCH 0/2] DS1374 Watchdog fixes Guenter Roeck
2017-04-25  5:03   ` [rtc-linux] " Guenter Roeck
2017-04-25 14:55   ` Moritz Fischer
2017-04-25 14:55     ` [rtc-linux] " Moritz Fischer
2017-04-25 16:17     ` Guenter Roeck
2017-04-25 16:17       ` [rtc-linux] " Guenter Roeck
2017-04-25 16:32       ` Alexandre Belloni
2017-04-25 16:32         ` [rtc-linux] " Alexandre Belloni
2017-04-25 16:58         ` Guenter Roeck
2017-04-25 16:58           ` [rtc-linux] " Guenter Roeck
2017-04-25 19:58           ` Moritz Fischer
2017-04-25 19:58             ` [rtc-linux] " Moritz Fischer
2017-04-25 20:22             ` Guenter Roeck
2017-04-25 20:22               ` [rtc-linux] " Guenter Roeck
2017-04-25 20:34               ` Moritz Fischer
2017-04-25 20:34                 ` [rtc-linux] " Moritz Fischer
2017-04-25 21:05                 ` Guenter Roeck
2017-04-25 21:05                   ` [rtc-linux] " Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1493071512-5718-2-git-send-email-mdf@kernel.org \
    --to=mdf@kernel.org \
    --cc=a.zummo@towertech.it \
    --cc=alex.williams@ni.com \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=moritz.fischer@ettus.com \
    --cc=rtc-linux@googlegroups.com \
    --cc=wim@iguana.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.