diff options
author | Henrik Rydberg <rydberg@euromail.se> | 2012-09-01 03:27:20 -0400 |
---|---|---|
committer | Henrik Rydberg <rydberg@euromail.se> | 2012-09-19 13:50:19 -0400 |
commit | 17a465a7f2d6ce31738a3a76591afeab165f185a (patch) | |
tree | b10a27eb43a6eb0aee31aa851c00936ec3edcc17 | |
parent | 7c1a87897c75139dec258eb03e1a24fb73385b73 (diff) |
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>
-rw-r--r-- | drivers/input/input-mt.c | 32 | ||||
-rw-r--r-- | include/linux/input/mt.h | 4 |
2 files changed, 36 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, | |||
383 | return 0; | 383 | return 0; |
384 | } | 384 | } |
385 | EXPORT_SYMBOL(input_mt_assign_slots); | 385 | EXPORT_SYMBOL(input_mt_assign_slots); |
386 | |||
387 | /** | ||
388 | * input_mt_get_slot_by_key() - return slot matching key | ||
389 | * @dev: input device with allocated MT slots | ||
390 | * @key: the key of the sought slot | ||
391 | * | ||
392 | * Returns the slot of the given key, if it exists, otherwise | ||
393 | * set the key on the first unused slot and return. | ||
394 | * | ||
395 | * If no available slot can be found, -1 is returned. | ||
396 | */ | ||
397 | int input_mt_get_slot_by_key(struct input_dev *dev, int key) | ||
398 | { | ||
399 | struct input_mt *mt = dev->mt; | ||
400 | struct input_mt_slot *s; | ||
401 | |||
402 | if (!mt) | ||
403 | return -1; | ||
404 | |||
405 | for (s = mt->slots; s != mt->slots + mt->num_slots; s++) | ||
406 | if (input_mt_is_active(s) && s->key == key) | ||
407 | return s - mt->slots; | ||
408 | |||
409 | for (s = mt->slots; s != mt->slots + mt->num_slots; s++) | ||
410 | if (!input_mt_is_active(s)) { | ||
411 | s->key = key; | ||
412 | return s - mt->slots; | ||
413 | } | ||
414 | |||
415 | return -1; | ||
416 | } | ||
417 | EXPORT_SYMBOL(input_mt_get_slot_by_key); | ||
diff --git a/include/linux/input/mt.h b/include/linux/input/mt.h index 6b6f7c8e95bf..cc5cca774bab 100644 --- a/include/linux/input/mt.h +++ b/include/linux/input/mt.h | |||
@@ -24,10 +24,12 @@ | |||
24 | * struct input_mt_slot - represents the state of an input MT slot | 24 | * struct input_mt_slot - represents the state of an input MT slot |
25 | * @abs: holds current values of ABS_MT axes for this slot | 25 | * @abs: holds current values of ABS_MT axes for this slot |
26 | * @frame: last frame at which input_mt_report_slot_state() was called | 26 | * @frame: last frame at which input_mt_report_slot_state() was called |
27 | * @key: optional driver designation of this slot | ||
27 | */ | 28 | */ |
28 | struct input_mt_slot { | 29 | struct input_mt_slot { |
29 | int abs[ABS_MT_LAST - ABS_MT_FIRST + 1]; | 30 | int abs[ABS_MT_LAST - ABS_MT_FIRST + 1]; |
30 | unsigned int frame; | 31 | unsigned int frame; |
32 | unsigned int key; | ||
31 | }; | 33 | }; |
32 | 34 | ||
33 | /** | 35 | /** |
@@ -111,4 +113,6 @@ struct input_mt_pos { | |||
111 | int input_mt_assign_slots(struct input_dev *dev, int *slots, | 113 | int input_mt_assign_slots(struct input_dev *dev, int *slots, |
112 | const struct input_mt_pos *pos, int num_pos); | 114 | const struct input_mt_pos *pos, int num_pos); |
113 | 115 | ||
116 | int input_mt_get_slot_by_key(struct input_dev *dev, int key); | ||
117 | |||
114 | #endif | 118 | #endif |