Commit 96098274 authored by Benjamin Tissoires's avatar Benjamin Tissoires Committed by Jiri Kosina

HID: multitouch: optimize the sticky fingers timer

Instead of unconditionally expiring the timer and calling a long
mt_release_contacts(), we can check if some slots are used when the
timer expires.

We can also remove the timer if we happen to receive all the releases.

The logic behind the MT_IO_FLAGS_PENDING_SLOTS could be implemented by
counting how many slots are active, but using bits feels slightly more
efficient.
Signed-off-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Tested-by: default avatarArek Burdach <arek.burdach@gmail.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 4f4001bc
...@@ -79,6 +79,8 @@ MODULE_LICENSE("GPL"); ...@@ -79,6 +79,8 @@ MODULE_LICENSE("GPL");
#define MT_BUTTONTYPE_CLICKPAD 0 #define MT_BUTTONTYPE_CLICKPAD 0
#define MT_IO_FLAGS_RUNNING 0 #define MT_IO_FLAGS_RUNNING 0
#define MT_IO_FLAGS_ACTIVE_SLOTS 1
#define MT_IO_FLAGS_PENDING_SLOTS 2
struct mt_slot { struct mt_slot {
__s32 x, y, cx, cy, p, w, h; __s32 x, y, cx, cy, p, w, h;
...@@ -705,6 +707,8 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input) ...@@ -705,6 +707,8 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p); input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major); input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor); input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
} }
} }
...@@ -720,6 +724,11 @@ static void mt_sync_frame(struct mt_device *td, struct input_dev *input) ...@@ -720,6 +724,11 @@ static void mt_sync_frame(struct mt_device *td, struct input_dev *input)
input_mt_sync_frame(input); input_mt_sync_frame(input);
input_sync(input); input_sync(input);
td->num_received = 0; td->num_received = 0;
if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags))
set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
else
clear_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
clear_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
} }
static int mt_touch_event(struct hid_device *hid, struct hid_field *field, static int mt_touch_event(struct hid_device *hid, struct hid_field *field,
...@@ -859,8 +868,13 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report) ...@@ -859,8 +868,13 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
* only affect laggish machines and the ones that have a firmware * only affect laggish machines and the ones that have a firmware
* defect. * defect.
*/ */
if (td->mtclass.quirks & MT_QUIRK_STICKY_FINGERS) if (td->mtclass.quirks & MT_QUIRK_STICKY_FINGERS) {
mod_timer(&td->release_timer, jiffies + msecs_to_jiffies(100)); if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
mod_timer(&td->release_timer,
jiffies + msecs_to_jiffies(100));
else
del_timer(&td->release_timer);
}
clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags); clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
} }
...@@ -1210,6 +1224,7 @@ static void mt_expired_timeout(unsigned long arg) ...@@ -1210,6 +1224,7 @@ static void mt_expired_timeout(unsigned long arg)
*/ */
if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags)) if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
return; return;
if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
mt_release_contacts(hdev); mt_release_contacts(hdev);
clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags); clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment