Input: Use accessor for MT values

The current MT accessor function does not distinguish between the MT
values and the slot specification event. Add an accessor function for
the values only, and use it where appropriate.

Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Change-Id: Ic1f230bb14bb5065ae5831e2ca88568152cede19
Input: Add enabled device attribute

Allows closing the hardware device while the input device is open.

Signed-off-by: Arve Hjønnevåg <arve@android.com>
Change-Id: I91b6e24f14b3334d17bfe8e5f86d2b33c85e1ea1
Input: Set users to 0 when an input device is disabled though sysfs

Some drivers check dev->users suspend and resume. If the device
was turned off with the sysfs hook, it should not turn back on
in resume.

Signed-off-by: Arve Hjønnevåg <arve@android.com>
Change-Id: Iff17fdac307ec9c27744ac886f9dc94aac665c80
Input: add infrastructure for selecting clockid for event time stamps

As noted by Arve and others, since wall time can jump backwards, it is
difficult to use for input because one cannot determine if one event
occurred before another or for how long a key was pressed.

However, the timestamp field is part of the kernel ABI, and cannot be
changed without possibly breaking existing users.

This patch adds a new IOCTL that allows a clockid to be set in the
evdev_client struct that will specify which time base to use for event
timestamps (ie: CLOCK_MONOTONIC instead of CLOCK_REALTIME).

For now we only support CLOCK_MONOTONIC and CLOCK_REALTIME, but
in the future we could support other clockids if appropriate.

The default remains CLOCK_REALTIME, so we don't change the ABI.

Signed-off-by: John Stultz <john.stultz@linaro.org>
Reviewed-by: Daniel Kurtz <djkurtz@google.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

Change-Id: I9d34528d467501d5fac948d85f81b61c0e82fd2f
Input: Add EVIOC mechanism for MT slots

This patch adds the ability to extract MT slot data via a new ioctl,
EVIOCGMTSLOTS. The function returns an array of slot values for the
specified ABS_MT event type.

Example of user space usage:

struct { unsigned code; int values[64]; } req;
req.code = ABS_MT_POSITION_X;
if (ioctl(fd, EVIOCGMTSLOTS(sizeof(req)), &req) < 0)
	return -1;
for (i = 0; i < 64; i++)
	printf("slot %d: %d\n", i, req.values[i]);

Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Change-Id: I7bb37860aac3bc5c9f064bd0622ed87ee7410b63
Input: evdev - fix variable initialisation

Commit 509f87c5f564 (evdev - do not block waiting for an event if fd
is nonblock) created a code path were it was possible to use retval
uninitialized.

This could lead to the xorg evdev input driver getting corrupt data
and refusing to work with log messages like
	AUO-Pixcir touchscreen: Read error: Success
	sg060_keys: Read error: Success
	AUO-Pixcir touchscreen: Read error: Success
	sg060_keys: Read error: Success
(for drivers auo-pixcir-ts and gpio-keys).

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Acked-by: Dima Zavin <dima@android.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Change-Id: Ic6df546ad278988be369fba4e0bf5e8f0a974bb6
input: keyreset: process pressed keys at init

Bug: 7344361
Signed-off-by: Dima Zavin <dima@android.com>
Change-Id: I92c9ec8a7d2882f280af9a5807a6052e54ecc16a
input: keyreset: move init to subsys to be ready early

Bug: 7344361
Signed-off-by: Dima Zavin <dima@android.com>
Change-Id: I3564a354fddd69f352704c9e819ea4538096264a
input: keyreset: add support for reset after timeout

If a timeout is requested, a delayed work item will be
scheduled to restart the device. If the keys are released
before the timeout expires, the reset is aborted.

As expected, the reset_fn can be used to reset the device
after the timeout.

Bug: 7344361
Signed-off-by: Dima Zavin <dima@android.com>
Change-Id: I1d77cdb3dcc63f579b1250506f0a30de1e033d67
Input: polldev - immediately poll device upon opening

To allow open/ioctl(EVIOCGABS)/close use pattern for polled devices read
the device in context of open() call instead of offloading the first read
to a workqueue. This will ensure that once call to open() returns device
would have cached reasonably recent axis values that can be retrieved via
appropriate ioctl.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Change-Id: I87bce80da48ee4676bf3acb2106f7561503ac279
Input: force feedback - potential integer wrap in input_ff_create()

The problem here is that max_effects can wrap on 32 bits systems.
We'd allocate a smaller amount of data than sizeof(struct ff_device).
The call to kcalloc() on the next line would fail but it would write
the NULL return outside of the memory we just allocated causing data
corruption.

The call path is that uinput_setup_device() get ->ff_effects_max from
the user and sets the value in the ->private_data struct.  From there
it is:
-> uinput_ioctl_handler()
   -> uinput_create_device()
      -> input_ff_create(dev, udev->ff_effects_max);

I've also changed ff_effects_max so it's an unsigned int instead of
a signed int as a cleanup.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Change-Id: Icb43c9d25bf27f4c91569e06ffa4eeff2dc5b3ae
Input: Propagate hardware event timestamp to evdev.

Convey hardware timestamp associated with the current event packet.
The use of these event codes by hardware drivers is optional.
Used to reduce jitter and improve velocity tracking in ABS_MT devices.

Signed-off-by: Sasha Levitskiy <sanek@google.com>

Conflicts:
	drivers/input/evdev.c

Change-Id: I89f3a958944f6a2979964ee372e61bad448061b6