Skip to content

Commit 7d059ed

Browse files
PinglinuxJiri Kosina
authored andcommitted
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 <[email protected]> Reviewed-by: Jason Gerecke <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent f3586d2 commit 7d059ed

File tree

1 file changed

+33
-51
lines changed

1 file changed

+33
-51
lines changed

drivers/hid/wacom_wac.c

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,28 @@ static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
10651065
return 0;
10661066
}
10671067

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+
10681090
static int wacom_24hdt_irq(struct wacom_wac *wacom)
10691091
{
10701092
struct input_dev *input = wacom->input;
@@ -1075,7 +1097,6 @@ static int wacom_24hdt_irq(struct wacom_wac *wacom)
10751097
int num_contacts_left = 4; /* maximum contacts per packet */
10761098
int byte_per_packet = WACOM_BYTES_PER_24HDT_PACKET;
10771099
int y_offset = 2;
1078-
static int contact_with_no_pen_down_count = 0;
10791100

10801101
if (wacom->features.type == WACOM_27QHDT) {
10811102
current_num_contacts = data[63];
@@ -1088,10 +1109,8 @@ static int wacom_24hdt_irq(struct wacom_wac *wacom)
10881109
* First packet resets the counter since only the first
10891110
* packet in series will have non-zero current_num_contacts.
10901111
*/
1091-
if (current_num_contacts) {
1112+
if (current_num_contacts)
10921113
wacom->num_contacts_left = current_num_contacts;
1093-
contact_with_no_pen_down_count = 0;
1094-
}
10951114

10961115
contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
10971116

@@ -1124,15 +1143,14 @@ static int wacom_24hdt_irq(struct wacom_wac *wacom)
11241143
input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h));
11251144
input_report_abs(input, ABS_MT_ORIENTATION, w > h);
11261145
}
1127-
contact_with_no_pen_down_count++;
11281146
}
11291147
}
11301148
input_mt_sync_frame(input);
11311149

11321150
wacom->num_contacts_left -= contacts_to_send;
11331151
if (wacom->num_contacts_left <= 0) {
11341152
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);
11361154
}
11371155
return 1;
11381156
}
@@ -1145,7 +1163,6 @@ static int wacom_mt_touch(struct wacom_wac *wacom)
11451163
int current_num_contacts = data[2];
11461164
int contacts_to_send = 0;
11471165
int x_offset = 0;
1148-
static int contact_with_no_pen_down_count = 0;
11491166

11501167
/* MTTPC does not support Height and Width */
11511168
if (wacom->features.type == MTTPC || wacom->features.type == MTTPC_B)
@@ -1155,10 +1172,8 @@ static int wacom_mt_touch(struct wacom_wac *wacom)
11551172
* First packet resets the counter since only the first
11561173
* packet in series will have non-zero current_num_contacts.
11571174
*/
1158-
if (current_num_contacts) {
1175+
if (current_num_contacts)
11591176
wacom->num_contacts_left = current_num_contacts;
1160-
contact_with_no_pen_down_count = 0;
1161-
}
11621177

11631178
/* There are at most 5 contacts per packet */
11641179
contacts_to_send = min(5, wacom->num_contacts_left);
@@ -1179,15 +1194,14 @@ static int wacom_mt_touch(struct wacom_wac *wacom)
11791194
int y = get_unaligned_le16(&data[offset + x_offset + 9]);
11801195
input_report_abs(input, ABS_MT_POSITION_X, x);
11811196
input_report_abs(input, ABS_MT_POSITION_Y, y);
1182-
contact_with_no_pen_down_count++;
11831197
}
11841198
}
11851199
input_mt_sync_frame(input);
11861200

11871201
wacom->num_contacts_left -= contacts_to_send;
11881202
if (wacom->num_contacts_left <= 0) {
11891203
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);
11911205
}
11921206
return 1;
11931207
}
@@ -1196,7 +1210,6 @@ static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
11961210
{
11971211
struct input_dev *input = wacom->input;
11981212
unsigned char *data = wacom->data;
1199-
int contact_with_no_pen_down_count = 0;
12001213
int i;
12011214

12021215
for (i = 0; i < 2; i++) {
@@ -1211,13 +1224,12 @@ static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
12111224

12121225
input_report_abs(input, ABS_MT_POSITION_X, x);
12131226
input_report_abs(input, ABS_MT_POSITION_Y, y);
1214-
contact_with_no_pen_down_count++;
12151227
}
12161228
}
12171229
input_mt_sync_frame(input);
12181230

12191231
/* 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);
12211233

12221234
return 1;
12231235
}
@@ -1545,29 +1557,6 @@ static int wacom_wac_finger_event(struct hid_device *hdev,
15451557
return 0;
15461558
}
15471559

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-
15711560
static void wacom_wac_finger_report(struct hid_device *hdev,
15721561
struct hid_report *report)
15731562
{
@@ -1582,7 +1571,7 @@ static void wacom_wac_finger_report(struct hid_device *hdev,
15821571
input_sync(input);
15831572

15841573
/* 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);
15861575
}
15871576

15881577
void wacom_wac_usage_mapping(struct hid_device *hdev,
@@ -1642,7 +1631,6 @@ static int wacom_bpt_touch(struct wacom_wac *wacom)
16421631
struct input_dev *pad_input = wacom->pad_input;
16431632
unsigned char *data = wacom->data;
16441633
int i;
1645-
int contact_with_no_pen_down_count = 0;
16461634

16471635
if (data[0] != 0x02)
16481636
return 0;
@@ -1670,7 +1658,6 @@ static int wacom_bpt_touch(struct wacom_wac *wacom)
16701658
}
16711659
input_report_abs(input, ABS_MT_POSITION_X, x);
16721660
input_report_abs(input, ABS_MT_POSITION_Y, y);
1673-
contact_with_no_pen_down_count++;
16741661
}
16751662
}
16761663

@@ -1680,20 +1667,20 @@ static int wacom_bpt_touch(struct wacom_wac *wacom)
16801667
input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0);
16811668
input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0);
16821669
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);
16841671

16851672
return 1;
16861673
}
16871674

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)
16891676
{
16901677
struct wacom_features *features = &wacom->features;
16911678
struct input_dev *input = wacom->input;
16921679
bool touch = data[1] & 0x80;
16931680
int slot = input_mt_get_slot_by_key(input, data[0]);
16941681

16951682
if (slot < 0)
1696-
return 0;
1683+
return;
16971684

16981685
touch = touch && !wacom->shared->stylus_in_proximity;
16991686

@@ -1725,9 +1712,7 @@ static int wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data, in
17251712
input_report_abs(input, ABS_MT_POSITION_Y, y);
17261713
input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
17271714
input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
1728-
last_touch_count++;
17291715
}
1730-
return last_touch_count;
17311716
}
17321717

17331718
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)
17521737
unsigned char *data = wacom->data;
17531738
int count = data[1] & 0x07;
17541739
int i;
1755-
int contact_with_no_pen_down_count = 0;
17561740

17571741
if (data[0] != 0x02)
17581742
return 0;
@@ -1763,15 +1747,13 @@ static int wacom_bpt3_touch(struct wacom_wac *wacom)
17631747
int msg_id = data[offset];
17641748

17651749
if (msg_id >= 2 && msg_id <= 17)
1766-
contact_with_no_pen_down_count =
1767-
wacom_bpt3_touch_msg(wacom, data + offset,
1768-
contact_with_no_pen_down_count);
1750+
wacom_bpt3_touch_msg(wacom, data + offset);
17691751
else if (msg_id == 128)
17701752
wacom_bpt3_button_msg(wacom, data + offset);
17711753

17721754
}
17731755
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);
17751757

17761758
return 1;
17771759
}

0 commit comments

Comments
 (0)