]> git.openfabrics.org - ~shefty/rdma-dev.git/commitdiff
Input: Break out MT data
authorHenrik Rydberg <rydberg@euromail.se>
Sat, 15 Sep 2012 13:15:58 +0000 (15:15 +0200)
committerHenrik Rydberg <rydberg@euromail.se>
Wed, 19 Sep 2012 17:50:17 +0000 (19:50 +0200)
Move all MT-related things to a separate place. This saves some
bytes for non-mt input devices, and prepares for new MT features.

Reviewed-and-tested-by: Benjamin Tissoires <benjamin.tissoires@enac.fr>
Tested-by: Ping Cheng <pingc@wacom.com>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
drivers/input/evdev.c
drivers/input/input-mt.c
drivers/input/input.c
include/linux/input.h
include/linux/input/mt.h

index 6c58bfff01a3446b8dee0d7d51eeff1f98fbe2aa..a0692c551be52844728a80670c8f576658aa73de 100644 (file)
@@ -653,20 +653,22 @@ static int evdev_handle_mt_request(struct input_dev *dev,
                                   unsigned int size,
                                   int __user *ip)
 {
-       const struct input_mt_slot *mt = dev->mt;
+       const struct input_mt *mt = dev->mt;
        unsigned int code;
        int max_slots;
        int i;
 
        if (get_user(code, &ip[0]))
                return -EFAULT;
-       if (!input_is_mt_value(code))
+       if (!mt || !input_is_mt_value(code))
                return -EINVAL;
 
        max_slots = (size - sizeof(__u32)) / sizeof(__s32);
-       for (i = 0; i < dev->mtsize && i < max_slots; i++)
-               if (put_user(input_mt_get_value(&mt[i], code), &ip[1 + i]))
+       for (i = 0; i < mt->num_slots && i < max_slots; i++) {
+               int value = input_mt_get_value(&mt->slots[i], code);
+               if (put_user(value, &ip[1 + i]))
                        return -EFAULT;
+       }
 
        return 0;
 }
index 70a16c7da8ccbefc542477e27623a8641c72ad25..37ee1f925d232a67d4a6053ea1025922c17ed14b 100644 (file)
  */
 int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots)
 {
+       struct input_mt *mt = dev->mt;
        int i;
 
        if (!num_slots)
                return 0;
-       if (dev->mt)
-               return dev->mtsize != num_slots ? -EINVAL : 0;
+       if (mt)
+               return mt->num_slots != num_slots ? -EINVAL : 0;
 
-       dev->mt = kcalloc(num_slots, sizeof(struct input_mt_slot), GFP_KERNEL);
-       if (!dev->mt)
+       mt = kzalloc(sizeof(*mt) + num_slots * sizeof(*mt->slots), GFP_KERNEL);
+       if (!mt)
                return -ENOMEM;
 
-       dev->mtsize = num_slots;
+       mt->num_slots = num_slots;
        input_set_abs_params(dev, ABS_MT_SLOT, 0, num_slots - 1, 0, 0);
        input_set_abs_params(dev, ABS_MT_TRACKING_ID, 0, TRKID_MAX, 0, 0);
        input_set_events_per_packet(dev, 6 * num_slots);
 
        /* Mark slots as 'unused' */
        for (i = 0; i < num_slots; i++)
-               input_mt_set_value(&dev->mt[i], ABS_MT_TRACKING_ID, -1);
+               input_mt_set_value(&mt->slots[i], ABS_MT_TRACKING_ID, -1);
 
+       dev->mt = mt;
        return 0;
 }
 EXPORT_SYMBOL(input_mt_init_slots);
@@ -62,9 +64,6 @@ void input_mt_destroy_slots(struct input_dev *dev)
 {
        kfree(dev->mt);
        dev->mt = NULL;
-       dev->mtsize = 0;
-       dev->slot = 0;
-       dev->trkid = 0;
 }
 EXPORT_SYMBOL(input_mt_destroy_slots);
 
@@ -83,18 +82,19 @@ EXPORT_SYMBOL(input_mt_destroy_slots);
 void input_mt_report_slot_state(struct input_dev *dev,
                                unsigned int tool_type, bool active)
 {
-       struct input_mt_slot *mt;
+       struct input_mt *mt = dev->mt;
+       struct input_mt_slot *slot;
        int id;
 
-       if (!dev->mt || !active) {
+       if (!mt || !active) {
                input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
                return;
        }
 
-       mt = &dev->mt[dev->slot];
-       id = input_mt_get_value(mt, ABS_MT_TRACKING_ID);
-       if (id < 0 || input_mt_get_value(mt, ABS_MT_TOOL_TYPE) != tool_type)
-               id = input_mt_new_trkid(dev);
+       slot = &mt->slots[mt->slot];
+       id = input_mt_get_value(slot, ABS_MT_TRACKING_ID);
+       if (id < 0 || input_mt_get_value(slot, ABS_MT_TOOL_TYPE) != tool_type)
+               id = input_mt_new_trkid(mt);
 
        input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, id);
        input_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, tool_type);
@@ -135,13 +135,19 @@ EXPORT_SYMBOL(input_mt_report_finger_count);
  */
 void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count)
 {
-       struct input_mt_slot *oldest = NULL;
-       int oldid = dev->trkid;
-       int count = 0;
-       int i;
+       struct input_mt *mt = dev->mt;
+       struct input_mt_slot *oldest;
+       int oldid, count, i;
+
+       if (!mt)
+               return;
+
+       oldest = 0;
+       oldid = mt->trkid;
+       count = 0;
 
-       for (i = 0; i < dev->mtsize; ++i) {
-               struct input_mt_slot *ps = &dev->mt[i];
+       for (i = 0; i < mt->num_slots; ++i) {
+               struct input_mt_slot *ps = &mt->slots[i];
                int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID);
 
                if (id < 0)
index 8921c6180c51dfe0efadeef0e7be59878aeca252..79a4a2ad74de24a08d11eeb703b34833c96776b2 100644 (file)
@@ -166,6 +166,7 @@ static void input_stop_autorepeat(struct input_dev *dev)
 static int input_handle_abs_event(struct input_dev *dev,
                                  unsigned int code, int *pval)
 {
+       struct input_mt *mt = dev->mt;
        bool is_mt_event;
        int *pold;
 
@@ -174,8 +175,8 @@ static int input_handle_abs_event(struct input_dev *dev,
                 * "Stage" the event; we'll flush it later, when we
                 * get actual touch data.
                 */
-               if (*pval >= 0 && *pval < dev->mtsize)
-                       dev->slot = *pval;
+               if (mt && *pval >= 0 && *pval < mt->num_slots)
+                       mt->slot = *pval;
 
                return INPUT_IGNORE_EVENT;
        }
@@ -184,9 +185,8 @@ static int input_handle_abs_event(struct input_dev *dev,
 
        if (!is_mt_event) {
                pold = &dev->absinfo[code].value;
-       } else if (dev->mt) {
-               struct input_mt_slot *mtslot = &dev->mt[dev->slot];
-               pold = &mtslot->abs[code - ABS_MT_FIRST];
+       } else if (mt) {
+               pold = &mt->slots[mt->slot].abs[code - ABS_MT_FIRST];
        } else {
                /*
                 * Bypass filtering for multi-touch events when
@@ -205,9 +205,9 @@ static int input_handle_abs_event(struct input_dev *dev,
        }
 
        /* Flush pending "slot" event */
-       if (is_mt_event && dev->slot != input_abs_get_val(dev, ABS_MT_SLOT)) {
-               input_abs_set_val(dev, ABS_MT_SLOT, dev->slot);
-               input_pass_event(dev, EV_ABS, ABS_MT_SLOT, dev->slot);
+       if (is_mt_event && mt && mt->slot != input_abs_get_val(dev, ABS_MT_SLOT)) {
+               input_abs_set_val(dev, ABS_MT_SLOT, mt->slot);
+               input_pass_event(dev, EV_ABS, ABS_MT_SLOT, mt->slot);
        }
 
        return INPUT_PASS_TO_HANDLERS;
@@ -1751,8 +1751,8 @@ static unsigned int input_estimate_events_per_packet(struct input_dev *dev)
        int i;
        unsigned int events;
 
-       if (dev->mtsize) {
-               mt_slots = dev->mtsize;
+       if (dev->mt) {
+               mt_slots = dev->mt->num_slots;
        } else if (test_bit(ABS_MT_TRACKING_ID, dev->absbit)) {
                mt_slots = dev->absinfo[ABS_MT_TRACKING_ID].maximum -
                           dev->absinfo[ABS_MT_TRACKING_ID].minimum + 1,
index 725dcd0f63a4bf262f05555c528a20c68d8b1a75..9da4f5796fd63e35c35759ad4e7dba069ce0213a 100644 (file)
@@ -1203,11 +1203,7 @@ struct ff_effect {
  *     software autorepeat
  * @timer: timer for software autorepeat
  * @rep: current values for autorepeat parameters (delay, rate)
- * @mt: pointer to array of struct input_mt_slot holding current values
- *     of tracked contacts
- * @mtsize: number of MT slots the device uses
- * @slot: MT slot currently being transmitted
- * @trkid: stores MT tracking ID for the current contact
+ * @mt: pointer to multitouch state
  * @absinfo: array of &struct input_absinfo elements holding information
  *     about absolute axes (current value, min, max, flat, fuzz,
  *     resolution)
@@ -1287,10 +1283,7 @@ struct input_dev {
 
        int rep[REP_CNT];
 
-       struct input_mt_slot *mt;
-       int mtsize;
-       int slot;
-       int trkid;
+       struct input_mt *mt;
 
        struct input_absinfo *absinfo;
 
index f86737586e190364a09c882afbab7890e66bde04..63458bced77d8338963af873978e0a3feae0988f 100644 (file)
@@ -23,6 +23,20 @@ struct input_mt_slot {
        int abs[ABS_MT_LAST - ABS_MT_FIRST + 1];
 };
 
+/**
+ * struct input_mt - state of tracked contacts
+ * @trkid: stores MT tracking ID for the next contact
+ * @num_slots: number of MT slots the device uses
+ * @slot: MT slot currently being transmitted
+ * @slots: array of slots holding current values of tracked contacts
+ */
+struct input_mt {
+       int trkid;
+       int num_slots;
+       int slot;
+       struct input_mt_slot slots[];
+};
+
 static inline void input_mt_set_value(struct input_mt_slot *slot,
                                      unsigned code, int value)
 {
@@ -38,9 +52,9 @@ static inline int input_mt_get_value(const struct input_mt_slot *slot,
 int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots);
 void input_mt_destroy_slots(struct input_dev *dev);
 
-static inline int input_mt_new_trkid(struct input_dev *dev)
+static inline int input_mt_new_trkid(struct input_mt *mt)
 {
-       return dev->trkid++ & TRKID_MAX;
+       return mt->trkid++ & TRKID_MAX;
 }
 
 static inline void input_mt_slot(struct input_dev *dev, int slot)