]> git.openfabrics.org - ~shefty/rdma-dev.git/commitdiff
Input: MT - Get slot by key
authorHenrik Rydberg <rydberg@euromail.se>
Sat, 1 Sep 2012 07:27:20 +0000 (09:27 +0200)
committerHenrik Rydberg <rydberg@euromail.se>
Wed, 19 Sep 2012 17:50:19 +0000 (19:50 +0200)
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>
drivers/input/input-mt.c
include/linux/input/mt.h

index caff298832a4abcabafc7fa786ebc7ad4de2b9c4..44f5a67aaa691927b35e446e512c3d646bd897b9 100644 (file)
@@ -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);
index 6b6f7c8e95bfaf5d8dc3e82f9dced72717ce1a63..cc5cca774bab14590e544f682c96a4ab72cd89c4 100644 (file)
  * 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