lkml.org 
[lkml]   [2012]   [Aug]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 12/20] Input: MT - Add slot assignment by id
Date
Some drivers produce their own tracking ids, which needs to be mapped
to slots. This patch provides that function.

Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
---
drivers/input/input-mt.c | 30 ++++++++++++++++++++++++++++++
include/linux/input/mt.h | 2 ++
2 files changed, 32 insertions(+)

diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c
index effea9b..a485014 100644
--- a/drivers/input/input-mt.c
+++ b/drivers/input/input-mt.c
@@ -383,3 +383,33 @@ int input_mt_assign_slots(struct input_dev *dev, int *slots,
return 0;
}
EXPORT_SYMBOL(input_mt_assign_slots);
+
+/**
+ * input_mt_assign_slot_by_id() - return matching slot
+ * @dev: input device with allocated MT slots
+ * @id: the sought tracking id
+ *
+ * Returns the slot of the given tracking id, if it exists. Otherwise,
+ * the first unused slot is returned.
+ *
+ * If no available slot can be found, -1 is returned.
+ */
+int input_mt_assign_slot_by_id(struct input_dev *dev, int id)
+{
+ 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_get_value(s, ABS_MT_TRACKING_ID) == id)
+ return s - mt->slots;
+
+ for (s = mt->slots; s != mt->slots + mt->num_slots; s++)
+ if (!input_mt_is_active(s))
+ return s - mt->slots;
+
+ return -1;
+}
+EXPORT_SYMBOL(input_mt_assign_slot_by_id);
diff --git a/include/linux/input/mt.h b/include/linux/input/mt.h
index 10bb77c..54b640b 100644
--- a/include/linux/input/mt.h
+++ b/include/linux/input/mt.h
@@ -109,4 +109,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_assign_slot_by_id(struct input_dev *dev, int id);
+
#endif
--
1.7.12


\
 
 \ /
  Last update: 2012-08-26 15:21    [W:0.139 / U:0.104 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site