diff options
author | Ping Cheng <pinglinux@gmail.com> | 2015-03-20 17:57:21 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2015-04-02 08:13:42 -0400 |
commit | 7d059ed01ca18d20e0a94ef785ee81a45c19d78c (patch) | |
tree | 134797c4b913af172094fa46f99a22f7de5a4f93 /drivers/hid | |
parent | f3586d2f819af6dbe5b08d2a6f1d22b1a97e2b64 (diff) |
HID: wacom: use wacom_wac_finger_count_touches to set touch_down
Counting number of touching fingers by wacom_wac_finger_count_touches so we
don't have to count them inside individual routines.
Signed-off-by: Ping Cheng <pingc@wacom.com>
Reviewed-by: Jason Gerecke <jason.gerecke@wacom.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r-- | drivers/hid/wacom_wac.c | 84 |
1 files changed, 33 insertions, 51 deletions
diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 221443710aed..59b8e27909d4 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c | |||
@@ -1065,6 +1065,28 @@ static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len) | |||
1065 | return 0; | 1065 | return 0; |
1066 | } | 1066 | } |
1067 | 1067 | ||
1068 | static int wacom_wac_finger_count_touches(struct wacom_wac *wacom) | ||
1069 | { | ||
1070 | struct input_dev *input = wacom->input; | ||
1071 | unsigned touch_max = wacom->features.touch_max; | ||
1072 | int count = 0; | ||
1073 | int i; | ||
1074 | |||
1075 | /* non-HID_GENERIC single touch input doesn't call this routine */ | ||
1076 | if ((touch_max == 1) && (wacom->features.type == HID_GENERIC)) | ||
1077 | return wacom->hid_data.tipswitch && | ||
1078 | !wacom->shared->stylus_in_proximity; | ||
1079 | |||
1080 | for (i = 0; i < input->mt->num_slots; i++) { | ||
1081 | struct input_mt_slot *ps = &input->mt->slots[i]; | ||
1082 | int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID); | ||
1083 | if (id >= 0) | ||
1084 | count++; | ||
1085 | } | ||
1086 | |||
1087 | return count; | ||
1088 | } | ||
1089 | |||
1068 | static int wacom_24hdt_irq(struct wacom_wac *wacom) | 1090 | static int wacom_24hdt_irq(struct wacom_wac *wacom) |
1069 | { | 1091 | { |
1070 | struct input_dev *input = wacom->input; | 1092 | struct input_dev *input = wacom->input; |
@@ -1075,7 +1097,6 @@ static int wacom_24hdt_irq(struct wacom_wac *wacom) | |||
1075 | int num_contacts_left = 4; /* maximum contacts per packet */ | 1097 | int num_contacts_left = 4; /* maximum contacts per packet */ |
1076 | int byte_per_packet = WACOM_BYTES_PER_24HDT_PACKET; | 1098 | int byte_per_packet = WACOM_BYTES_PER_24HDT_PACKET; |
1077 | int y_offset = 2; | 1099 | int y_offset = 2; |
1078 | static int contact_with_no_pen_down_count = 0; | ||
1079 | 1100 | ||
1080 | if (wacom->features.type == WACOM_27QHDT) { | 1101 | if (wacom->features.type == WACOM_27QHDT) { |
1081 | current_num_contacts = data[63]; | 1102 | current_num_contacts = data[63]; |
@@ -1088,10 +1109,8 @@ static int wacom_24hdt_irq(struct wacom_wac *wacom) | |||
1088 | * First packet resets the counter since only the first | 1109 | * First packet resets the counter since only the first |
1089 | * packet in series will have non-zero current_num_contacts. | 1110 | * packet in series will have non-zero current_num_contacts. |
1090 | */ | 1111 | */ |
1091 | if (current_num_contacts) { | 1112 | if (current_num_contacts) |
1092 | wacom->num_contacts_left = current_num_contacts; | 1113 | wacom->num_contacts_left = current_num_contacts; |
1093 | contact_with_no_pen_down_count = 0; | ||
1094 | } | ||
1095 | 1114 | ||
1096 | contacts_to_send = min(num_contacts_left, wacom->num_contacts_left); | 1115 | contacts_to_send = min(num_contacts_left, wacom->num_contacts_left); |
1097 | 1116 | ||
@@ -1124,7 +1143,6 @@ static int wacom_24hdt_irq(struct wacom_wac *wacom) | |||
1124 | input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h)); | 1143 | input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h)); |
1125 | input_report_abs(input, ABS_MT_ORIENTATION, w > h); | 1144 | input_report_abs(input, ABS_MT_ORIENTATION, w > h); |
1126 | } | 1145 | } |
1127 | contact_with_no_pen_down_count++; | ||
1128 | } | 1146 | } |
1129 | } | 1147 | } |
1130 | input_mt_sync_frame(input); | 1148 | input_mt_sync_frame(input); |
@@ -1132,7 +1150,7 @@ static int wacom_24hdt_irq(struct wacom_wac *wacom) | |||
1132 | wacom->num_contacts_left -= contacts_to_send; | 1150 | wacom->num_contacts_left -= contacts_to_send; |
1133 | if (wacom->num_contacts_left <= 0) { | 1151 | if (wacom->num_contacts_left <= 0) { |
1134 | wacom->num_contacts_left = 0; | 1152 | wacom->num_contacts_left = 0; |
1135 | wacom->shared->touch_down = (contact_with_no_pen_down_count > 0); | 1153 | wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom); |
1136 | } | 1154 | } |
1137 | return 1; | 1155 | return 1; |
1138 | } | 1156 | } |
@@ -1145,7 +1163,6 @@ static int wacom_mt_touch(struct wacom_wac *wacom) | |||
1145 | int current_num_contacts = data[2]; | 1163 | int current_num_contacts = data[2]; |
1146 | int contacts_to_send = 0; | 1164 | int contacts_to_send = 0; |
1147 | int x_offset = 0; | 1165 | int x_offset = 0; |
1148 | static int contact_with_no_pen_down_count = 0; | ||
1149 | 1166 | ||
1150 | /* MTTPC does not support Height and Width */ | 1167 | /* MTTPC does not support Height and Width */ |
1151 | if (wacom->features.type == MTTPC || wacom->features.type == MTTPC_B) | 1168 | if (wacom->features.type == MTTPC || wacom->features.type == MTTPC_B) |
@@ -1155,10 +1172,8 @@ static int wacom_mt_touch(struct wacom_wac *wacom) | |||
1155 | * First packet resets the counter since only the first | 1172 | * First packet resets the counter since only the first |
1156 | * packet in series will have non-zero current_num_contacts. | 1173 | * packet in series will have non-zero current_num_contacts. |
1157 | */ | 1174 | */ |
1158 | if (current_num_contacts) { | 1175 | if (current_num_contacts) |
1159 | wacom->num_contacts_left = current_num_contacts; | 1176 | wacom->num_contacts_left = current_num_contacts; |
1160 | contact_with_no_pen_down_count = 0; | ||
1161 | } | ||
1162 | 1177 | ||
1163 | /* There are at most 5 contacts per packet */ | 1178 | /* There are at most 5 contacts per packet */ |
1164 | contacts_to_send = min(5, wacom->num_contacts_left); | 1179 | contacts_to_send = min(5, wacom->num_contacts_left); |
@@ -1179,7 +1194,6 @@ static int wacom_mt_touch(struct wacom_wac *wacom) | |||
1179 | int y = get_unaligned_le16(&data[offset + x_offset + 9]); | 1194 | int y = get_unaligned_le16(&data[offset + x_offset + 9]); |
1180 | input_report_abs(input, ABS_MT_POSITION_X, x); | 1195 | input_report_abs(input, ABS_MT_POSITION_X, x); |
1181 | input_report_abs(input, ABS_MT_POSITION_Y, y); | 1196 | input_report_abs(input, ABS_MT_POSITION_Y, y); |
1182 | contact_with_no_pen_down_count++; | ||
1183 | } | 1197 | } |
1184 | } | 1198 | } |
1185 | input_mt_sync_frame(input); | 1199 | input_mt_sync_frame(input); |
@@ -1187,7 +1201,7 @@ static int wacom_mt_touch(struct wacom_wac *wacom) | |||
1187 | wacom->num_contacts_left -= contacts_to_send; | 1201 | wacom->num_contacts_left -= contacts_to_send; |
1188 | if (wacom->num_contacts_left <= 0) { | 1202 | if (wacom->num_contacts_left <= 0) { |
1189 | wacom->num_contacts_left = 0; | 1203 | wacom->num_contacts_left = 0; |
1190 | wacom->shared->touch_down = (contact_with_no_pen_down_count > 0); | 1204 | wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom); |
1191 | } | 1205 | } |
1192 | return 1; | 1206 | return 1; |
1193 | } | 1207 | } |
@@ -1196,7 +1210,6 @@ static int wacom_tpc_mt_touch(struct wacom_wac *wacom) | |||
1196 | { | 1210 | { |
1197 | struct input_dev *input = wacom->input; | 1211 | struct input_dev *input = wacom->input; |
1198 | unsigned char *data = wacom->data; | 1212 | unsigned char *data = wacom->data; |
1199 | int contact_with_no_pen_down_count = 0; | ||
1200 | int i; | 1213 | int i; |
1201 | 1214 | ||
1202 | for (i = 0; i < 2; i++) { | 1215 | for (i = 0; i < 2; i++) { |
@@ -1211,13 +1224,12 @@ static int wacom_tpc_mt_touch(struct wacom_wac *wacom) | |||
1211 | 1224 | ||
1212 | input_report_abs(input, ABS_MT_POSITION_X, x); | 1225 | input_report_abs(input, ABS_MT_POSITION_X, x); |
1213 | input_report_abs(input, ABS_MT_POSITION_Y, y); | 1226 | input_report_abs(input, ABS_MT_POSITION_Y, y); |
1214 | contact_with_no_pen_down_count++; | ||
1215 | } | 1227 | } |
1216 | } | 1228 | } |
1217 | input_mt_sync_frame(input); | 1229 | input_mt_sync_frame(input); |
1218 | 1230 | ||
1219 | /* keep touch state for pen event */ | 1231 | /* keep touch state for pen event */ |
1220 | wacom->shared->touch_down = (contact_with_no_pen_down_count > 0); | 1232 | wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom); |
1221 | 1233 | ||
1222 | return 1; | 1234 | return 1; |
1223 | } | 1235 | } |
@@ -1545,29 +1557,6 @@ static int wacom_wac_finger_event(struct hid_device *hdev, | |||
1545 | return 0; | 1557 | return 0; |
1546 | } | 1558 | } |
1547 | 1559 | ||
1548 | static int wacom_wac_finger_count_touches(struct hid_device *hdev) | ||
1549 | { | ||
1550 | struct wacom *wacom = hid_get_drvdata(hdev); | ||
1551 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; | ||
1552 | struct input_dev *input = wacom_wac->input; | ||
1553 | unsigned touch_max = wacom_wac->features.touch_max; | ||
1554 | int count = 0; | ||
1555 | int i; | ||
1556 | |||
1557 | if (touch_max == 1) | ||
1558 | return wacom_wac->hid_data.tipswitch && | ||
1559 | !wacom_wac->shared->stylus_in_proximity; | ||
1560 | |||
1561 | for (i = 0; i < input->mt->num_slots; i++) { | ||
1562 | struct input_mt_slot *ps = &input->mt->slots[i]; | ||
1563 | int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID); | ||
1564 | if (id >= 0) | ||
1565 | count++; | ||
1566 | } | ||
1567 | |||
1568 | return count; | ||
1569 | } | ||
1570 | |||
1571 | static void wacom_wac_finger_report(struct hid_device *hdev, | 1560 | static void wacom_wac_finger_report(struct hid_device *hdev, |
1572 | struct hid_report *report) | 1561 | struct hid_report *report) |
1573 | { | 1562 | { |
@@ -1582,7 +1571,7 @@ static void wacom_wac_finger_report(struct hid_device *hdev, | |||
1582 | input_sync(input); | 1571 | input_sync(input); |
1583 | 1572 | ||
1584 | /* keep touch state for pen event */ | 1573 | /* keep touch state for pen event */ |
1585 | wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(hdev); | 1574 | wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac); |
1586 | } | 1575 | } |
1587 | 1576 | ||
1588 | void wacom_wac_usage_mapping(struct hid_device *hdev, | 1577 | void wacom_wac_usage_mapping(struct hid_device *hdev, |
@@ -1642,7 +1631,6 @@ static int wacom_bpt_touch(struct wacom_wac *wacom) | |||
1642 | struct input_dev *pad_input = wacom->pad_input; | 1631 | struct input_dev *pad_input = wacom->pad_input; |
1643 | unsigned char *data = wacom->data; | 1632 | unsigned char *data = wacom->data; |
1644 | int i; | 1633 | int i; |
1645 | int contact_with_no_pen_down_count = 0; | ||
1646 | 1634 | ||
1647 | if (data[0] != 0x02) | 1635 | if (data[0] != 0x02) |
1648 | return 0; | 1636 | return 0; |
@@ -1670,7 +1658,6 @@ static int wacom_bpt_touch(struct wacom_wac *wacom) | |||
1670 | } | 1658 | } |
1671 | input_report_abs(input, ABS_MT_POSITION_X, x); | 1659 | input_report_abs(input, ABS_MT_POSITION_X, x); |
1672 | input_report_abs(input, ABS_MT_POSITION_Y, y); | 1660 | input_report_abs(input, ABS_MT_POSITION_Y, y); |
1673 | contact_with_no_pen_down_count++; | ||
1674 | } | 1661 | } |
1675 | } | 1662 | } |
1676 | 1663 | ||
@@ -1680,12 +1667,12 @@ static int wacom_bpt_touch(struct wacom_wac *wacom) | |||
1680 | input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0); | 1667 | input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0); |
1681 | input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0); | 1668 | input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0); |
1682 | input_report_key(pad_input, BTN_RIGHT, (data[1] & 0x01) != 0); | 1669 | input_report_key(pad_input, BTN_RIGHT, (data[1] & 0x01) != 0); |
1683 | wacom->shared->touch_down = (contact_with_no_pen_down_count > 0); | 1670 | wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom); |
1684 | 1671 | ||
1685 | return 1; | 1672 | return 1; |
1686 | } | 1673 | } |
1687 | 1674 | ||
1688 | static int wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data, int last_touch_count) | 1675 | static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data) |
1689 | { | 1676 | { |
1690 | struct wacom_features *features = &wacom->features; | 1677 | struct wacom_features *features = &wacom->features; |
1691 | struct input_dev *input = wacom->input; | 1678 | struct input_dev *input = wacom->input; |
@@ -1693,7 +1680,7 @@ static int wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data, in | |||
1693 | int slot = input_mt_get_slot_by_key(input, data[0]); | 1680 | int slot = input_mt_get_slot_by_key(input, data[0]); |
1694 | 1681 | ||
1695 | if (slot < 0) | 1682 | if (slot < 0) |
1696 | return 0; | 1683 | return; |
1697 | 1684 | ||
1698 | touch = touch && !wacom->shared->stylus_in_proximity; | 1685 | touch = touch && !wacom->shared->stylus_in_proximity; |
1699 | 1686 | ||
@@ -1725,9 +1712,7 @@ static int wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data, in | |||
1725 | input_report_abs(input, ABS_MT_POSITION_Y, y); | 1712 | input_report_abs(input, ABS_MT_POSITION_Y, y); |
1726 | input_report_abs(input, ABS_MT_TOUCH_MAJOR, width); | 1713 | input_report_abs(input, ABS_MT_TOUCH_MAJOR, width); |
1727 | input_report_abs(input, ABS_MT_TOUCH_MINOR, height); | 1714 | input_report_abs(input, ABS_MT_TOUCH_MINOR, height); |
1728 | last_touch_count++; | ||
1729 | } | 1715 | } |
1730 | return last_touch_count; | ||
1731 | } | 1716 | } |
1732 | 1717 | ||
1733 | static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data) | 1718 | static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data) |
@@ -1752,7 +1737,6 @@ static int wacom_bpt3_touch(struct wacom_wac *wacom) | |||
1752 | unsigned char *data = wacom->data; | 1737 | unsigned char *data = wacom->data; |
1753 | int count = data[1] & 0x07; | 1738 | int count = data[1] & 0x07; |
1754 | int i; | 1739 | int i; |
1755 | int contact_with_no_pen_down_count = 0; | ||
1756 | 1740 | ||
1757 | if (data[0] != 0x02) | 1741 | if (data[0] != 0x02) |
1758 | return 0; | 1742 | return 0; |
@@ -1763,15 +1747,13 @@ static int wacom_bpt3_touch(struct wacom_wac *wacom) | |||
1763 | int msg_id = data[offset]; | 1747 | int msg_id = data[offset]; |
1764 | 1748 | ||
1765 | if (msg_id >= 2 && msg_id <= 17) | 1749 | if (msg_id >= 2 && msg_id <= 17) |
1766 | contact_with_no_pen_down_count = | 1750 | wacom_bpt3_touch_msg(wacom, data + offset); |
1767 | wacom_bpt3_touch_msg(wacom, data + offset, | ||
1768 | contact_with_no_pen_down_count); | ||
1769 | else if (msg_id == 128) | 1751 | else if (msg_id == 128) |
1770 | wacom_bpt3_button_msg(wacom, data + offset); | 1752 | wacom_bpt3_button_msg(wacom, data + offset); |
1771 | 1753 | ||
1772 | } | 1754 | } |
1773 | input_mt_sync_frame(input); | 1755 | input_mt_sync_frame(input); |
1774 | wacom->shared->touch_down = (contact_with_no_pen_down_count > 0); | 1756 | wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom); |
1775 | 1757 | ||
1776 | return 1; | 1758 | return 1; |
1777 | } | 1759 | } |