linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anshul Garg <aksgarg1989@gmail.com>
To: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Cc: aksgarg1989@gmail.com
Subject: [PATCH] Input/evdev: Add 64bit timestamp support
Date: Mon,  6 Jul 2015 12:33:44 -0700	[thread overview]
Message-ID: <1436211224-59601-1-git-send-email-aksgarg1989@gmail.com> (raw)
In-Reply-To: <aksgarg1989@gmail.com>

From: Anshul Garg <aksgarg1989@gmail.com>

As per current implementation input driver can only
send ktime converted to timeval which user space again
have to convert.
In some cases input drivers need 64bit timestamp value
from driver only so that same value can be used by upper
layer without any manipulation.
Proposed implementation is placed under CONFIG flag which
will not break any existing code.

Signed-off-by: Anshul Garg <aksgarg1989@gmail.com>
---
 drivers/input/Kconfig      |    8 ++++++++
 drivers/input/evdev.c      |   21 ++++++++++++++++++++-
 include/uapi/linux/input.h |    3 +++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index a35532e..9bf9044 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -161,6 +161,14 @@ config INPUT_EVDEV
 	  To compile this driver as a module, choose M here: the
 	  module will be called evdev.
 
+config INPUT_EVDEV_64BIT_TIMESTAMP
+       bool "64 Event timestamp"
+	depends on INPUT_EVDEV
+	default n
+	help
+          Say Y here if you need to send 64bit timestamp from input
+	   drivers otherwise N.
+
 config INPUT_EVBUG
 	tristate "Event debugging"
 	help
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 9d35499..396b60f 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -90,6 +90,9 @@ static void __evdev_flush_queue(struct evdev_client *client, unsigned int type)
 			continue;
 		} else if (head != i) {
 			/* move entry to fill the gap */
+#ifdef CONFIG_INPUT_EVDEV_64BIT_TIMESTAMP
+			client->buffer[head].timestamp = ev->timestamp;
+#endif
 			client->buffer[head].time = ev->time;
 			client->buffer[head].type = ev->type;
 			client->buffer[head].code = ev->code;
@@ -111,6 +114,9 @@ static void __evdev_flush_queue(struct evdev_client *client, unsigned int type)
 static void __evdev_queue_syn_dropped(struct evdev_client *client)
 {
 	struct input_event ev;
+#ifdef CONFIG_INPUT_EVDEV_64BIT_TIMESTAMP
+	struct timespec64 ts;
+#endif
 	ktime_t time;
 
 	time = client->clk_type == EV_CLK_REAL ?
@@ -118,7 +124,10 @@ static void __evdev_queue_syn_dropped(struct evdev_client *client)
 			client->clk_type == EV_CLK_MONO ?
 				ktime_get() :
 				ktime_get_boottime();
-
+#ifdef CONFIG_INPUT_EVDEV_64BIT_TIMESTAMP
+	ts = ktime_to_timespec64(time);
+	ev.timestamp = ts.tv_sec*NSEC_PER_SEC + ts.tv_nsec;
+#endif
 	ev.time = ktime_to_timeval(time);
 	ev.type = EV_SYN;
 	ev.code = SYN_DROPPED;
@@ -194,6 +203,9 @@ static void __pass_event(struct evdev_client *client,
 		 */
 		client->tail = (client->head - 2) & (client->bufsize - 1);
 
+#ifdef CONFIG_INPUT_EVDEV_64BIT_TIMESTAMP
+		client->buffer[client->tail].timestamp = event->timestamp;
+#endif
 		client->buffer[client->tail].time = event->time;
 		client->buffer[client->tail].type = EV_SYN;
 		client->buffer[client->tail].code = SYN_DROPPED;
@@ -215,6 +227,9 @@ static void evdev_pass_values(struct evdev_client *client,
 	struct evdev *evdev = client->evdev;
 	const struct input_value *v;
 	struct input_event event;
+#ifdef CONFIG_INPUT_EVDEV_64BIT_TIMESTAMP
+	struct timespec64 ts;
+#endif
 	bool wakeup = false;
 
 	if (client->revoked)
@@ -222,6 +237,10 @@ static void evdev_pass_values(struct evdev_client *client,
 
 	event.time = ktime_to_timeval(ev_time[client->clk_type]);
 
+#ifdef CONFIG_INPUT_EVDEV_64BIT_TIMESTAMP
+	ts = ktime_to_timespec64(ev_time[client->clk_type]);
+	event.timestamp = ts.tv_sec*NSEC_PER_SEC + ts.tv_nsec;
+#endif
 	/* Interrupts are disabled, just acquire the lock. */
 	spin_lock(&client->buffer_lock);
 
diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h
index 905d90c..e0e47bb 100644
--- a/include/uapi/linux/input.h
+++ b/include/uapi/linux/input.h
@@ -26,6 +26,9 @@ struct input_event {
 	__u16 type;
 	__u16 code;
 	__s32 value;
+#ifdef CONFIG_INPUT_EVDEV_64BIT_TIMESTAMP
+	__s64 timestamp;
+#endif
 };
 
 /*
-- 
1.7.9.5


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


             reply	other threads:[~2015-07-06 19:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-06 19:33 Anshul Garg [this message]
2015-07-06 22:48 ` [PATCH] Input/evdev: Add 64bit timestamp support Dmitry Torokhov
2015-07-07 14:00   ` Anshul Garg
2015-07-07 18:14     ` Dmitry Torokhov
2015-07-07 20:29       ` Anshul Garg

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=1436211224-59601-1-git-send-email-aksgarg1989@gmail.com \
    --to=aksgarg1989@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).