diff options
author | Henrik Rydberg <rydberg@euromail.se> | 2012-09-01 09:27:20 +0200 |
---|---|---|
committer | Henrik Rydberg <rydberg@euromail.se> | 2012-09-19 19:50:19 +0200 |
commit | 17a465a7f2d6ce31738a3a76591afeab165f185a (patch) | |
tree | b10a27eb43a6eb0aee31aa851c00936ec3edcc17 /drivers/input/input-mt.c | |
parent | 7c1a87897c75139dec258eb03e1a24fb73385b73 (diff) | |
download | linux-17a465a7f2d6ce31738a3a76591afeab165f185a.tar.gz linux-17a465a7f2d6ce31738a3a76591afeab165f185a.tar.bz2 linux-17a465a7f2d6ce31738a3a76591afeab165f185a.zip |
Input: MT - Get slot by key
Some devices use an internal key for tracking which cannot be directly
mapped to slots. This patch provides a key-to-slot mapping, which can
be used by drivers of such devices.
Reviewed-and-tested-by: Benjamin Tissoires <benjamin.tissoires@enac.fr>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'drivers/input/input-mt.c')
-rw-r--r-- | drivers/input/input-mt.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c index caff298832a4..44f5a67aaa69 100644 --- a/drivers/input/input-mt.c +++ b/drivers/input/input-mt.c @@ -383,3 +383,35 @@ int input_mt_assign_slots(struct input_dev *dev, int *slots, return 0; } EXPORT_SYMBOL(input_mt_assign_slots); + +/** + * input_mt_get_slot_by_key() - return slot matching key + * @dev: input device with allocated MT slots + * @key: the key of the sought slot + * + * Returns the slot of the given key, if it exists, otherwise + * set the key on the first unused slot and return. + * + * If no available slot can be found, -1 is returned. + */ +int input_mt_get_slot_by_key(struct input_dev *dev, int key) +{ + struct input_mt *mt = dev->mt; + struct input_mt_slot *s; + + if (!mt) + return -1; + + for (s = mt->slots; s != mt->slots + mt->num_slots; s++) + if (input_mt_is_active(s) && s->key == key) + return s - mt->slots; + + for (s = mt->slots; s != mt->slots + mt->num_slots; s++) + if (!input_mt_is_active(s)) { + s->key = key; + return s - mt->slots; + } + + return -1; +} +EXPORT_SYMBOL(input_mt_get_slot_by_key); |