diff options
author | Atif Niyaz <atifniyaz@google.com> | 2019-07-24 15:26:31 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2019-07-25 04:12:20 -0400 |
commit | 3b51c44bd6936e86a7180abd9aebc4387a479253 (patch) | |
tree | 307baa973004837a30e57d0a3dccc54f89e06604 /drivers/input/input.c | |
parent | c2433827c1a149b72f1413f0151155f6fa4b3214 (diff) |
Input: allow drivers specify timestamp for input events
Currently, evdev stamps events with timestamps acquired in evdev_events()
However, this timestamping may not be accurate in terms of measuring
when the actual event happened.
Let's allow individual drivers specify timestamp in order to provide a more
accurate sense of time for the event. It is expected that drivers will set the
timestamp in their hard interrupt routine.
Signed-off-by: Atif Niyaz <atifniyaz@google.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/input.c')
-rw-r--r-- | drivers/input/input.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c index 7f3c5fcb9ed6..7494a0dede79 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c | |||
@@ -1895,6 +1895,46 @@ void input_free_device(struct input_dev *dev) | |||
1895 | EXPORT_SYMBOL(input_free_device); | 1895 | EXPORT_SYMBOL(input_free_device); |
1896 | 1896 | ||
1897 | /** | 1897 | /** |
1898 | * input_set_timestamp - set timestamp for input events | ||
1899 | * @dev: input device to set timestamp for | ||
1900 | * @timestamp: the time at which the event has occurred | ||
1901 | * in CLOCK_MONOTONIC | ||
1902 | * | ||
1903 | * This function is intended to provide to the input system a more | ||
1904 | * accurate time of when an event actually occurred. The driver should | ||
1905 | * call this function as soon as a timestamp is acquired ensuring | ||
1906 | * clock conversions in input_set_timestamp are done correctly. | ||
1907 | * | ||
1908 | * The system entering suspend state between timestamp acquisition and | ||
1909 | * calling input_set_timestamp can result in inaccurate conversions. | ||
1910 | */ | ||
1911 | void input_set_timestamp(struct input_dev *dev, ktime_t timestamp) | ||
1912 | { | ||
1913 | dev->timestamp[INPUT_CLK_MONO] = timestamp; | ||
1914 | dev->timestamp[INPUT_CLK_REAL] = ktime_mono_to_real(timestamp); | ||
1915 | dev->timestamp[INPUT_CLK_BOOT] = ktime_mono_to_any(timestamp, | ||
1916 | TK_OFFS_BOOT); | ||
1917 | } | ||
1918 | EXPORT_SYMBOL(input_set_timestamp); | ||
1919 | |||
1920 | /** | ||
1921 | * input_get_timestamp - get timestamp for input events | ||
1922 | * @dev: input device to get timestamp from | ||
1923 | * | ||
1924 | * A valid timestamp is a timestamp of non-zero value. | ||
1925 | */ | ||
1926 | ktime_t *input_get_timestamp(struct input_dev *dev) | ||
1927 | { | ||
1928 | const ktime_t invalid_timestamp = ktime_set(0, 0); | ||
1929 | |||
1930 | if (!ktime_compare(dev->timestamp[INPUT_CLK_MONO], invalid_timestamp)) | ||
1931 | input_set_timestamp(dev, ktime_get()); | ||
1932 | |||
1933 | return dev->timestamp; | ||
1934 | } | ||
1935 | EXPORT_SYMBOL(input_get_timestamp); | ||
1936 | |||
1937 | /** | ||
1898 | * input_set_capability - mark device as capable of a certain event | 1938 | * input_set_capability - mark device as capable of a certain event |
1899 | * @dev: device that is capable of emitting or accepting event | 1939 | * @dev: device that is capable of emitting or accepting event |
1900 | * @type: type of the event (EV_KEY, EV_REL, etc...) | 1940 | * @type: type of the event (EV_KEY, EV_REL, etc...) |