aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/input-mt.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/input-mt.c')
-rw-r--r--drivers/input/input-mt.c32
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,
383 return 0; 383 return 0;
384} 384}
385EXPORT_SYMBOL(input_mt_assign_slots); 385EXPORT_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 */
397int 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}
417EXPORT_SYMBOL(input_mt_get_slot_by_key);