From 3431af5aad47a120cad7714a9b3a94fe528a2654 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 1 Sep 2012 09:27:20 +0200 Subject: [PATCH] --- yaml --- r: 323420 b: refs/heads/master c: 17a465a7f2d6ce31738a3a76591afeab165f185a h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/drivers/input/input-mt.c | 32 ++++++++++++++++++++++++++++++++ trunk/include/linux/input/mt.h | 4 ++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index b46f4c46dff5..e9551449c1a4 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 7c1a87897c75139dec258eb03e1a24fb73385b73 +refs/heads/master: 17a465a7f2d6ce31738a3a76591afeab165f185a diff --git a/trunk/drivers/input/input-mt.c b/trunk/drivers/input/input-mt.c index caff298832a4..44f5a67aaa69 100644 --- a/trunk/drivers/input/input-mt.c +++ b/trunk/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); diff --git a/trunk/include/linux/input/mt.h b/trunk/include/linux/input/mt.h index 6b6f7c8e95bf..cc5cca774bab 100644 --- a/trunk/include/linux/input/mt.h +++ b/trunk/include/linux/input/mt.h @@ -24,10 +24,12 @@ * struct input_mt_slot - represents the state of an input MT slot * @abs: holds current values of ABS_MT axes for this slot * @frame: last frame at which input_mt_report_slot_state() was called + * @key: optional driver designation of this slot */ struct input_mt_slot { int abs[ABS_MT_LAST - ABS_MT_FIRST + 1]; unsigned int frame; + unsigned int key; }; /** @@ -111,4 +113,6 @@ struct input_mt_pos { int input_mt_assign_slots(struct input_dev *dev, int *slots, const struct input_mt_pos *pos, int num_pos); +int input_mt_get_slot_by_key(struct input_dev *dev, int key); + #endif