Skip to content

Commit 19591e1

Browse files
jigpuJiri Kosina
authored andcommitted
HID: wacom: Support devices with two touchrings
If a device has more than one touchring, we want to be sure that userspace is able to distinguish them. Following previous standards, the first absolute ring will be reported as ABS_WHEEL and the second as ABS_THROTTLE. Relative rings will use REL_WHEEL_HI_RES / REL_WHEEL for the first and REL_HWHEEL_HI_RES / REL_HWHEEL for the second. Signed-off-by: Jason Gerecke <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 7ca234e commit 19591e1

File tree

2 files changed

+49
-12
lines changed

2 files changed

+49
-12
lines changed

drivers/hid/wacom_wac.c

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,10 +2047,21 @@ static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
20472047
break;
20482048
case WACOM_HID_WD_TOUCHRING:
20492049
if (field->flags & HID_MAIN_ITEM_RELATIVE) {
2050-
wacom_map_usage(input, usage, field, EV_REL, REL_WHEEL_HI_RES, 0);
2051-
set_bit(REL_WHEEL, input->relbit);
2050+
wacom_wac->relring_count++;
2051+
if (wacom_wac->relring_count == 1) {
2052+
wacom_map_usage(input, usage, field, EV_REL, REL_WHEEL_HI_RES, 0);
2053+
set_bit(REL_WHEEL, input->relbit);
2054+
}
2055+
else if (wacom_wac->relring_count == 2) {
2056+
wacom_map_usage(input, usage, field, EV_REL, REL_HWHEEL_HI_RES, 0);
2057+
set_bit(REL_HWHEEL, input->relbit);
2058+
}
20522059
} else {
2053-
wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
2060+
wacom_wac->absring_count++;
2061+
if (wacom_wac->absring_count == 1)
2062+
wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
2063+
else if (wacom_wac->absring_count == 2)
2064+
wacom_map_usage(input, usage, field, EV_ABS, ABS_THROTTLE, 0);
20542065
}
20552066
features->device_type |= WACOM_DEVICETYPE_PAD;
20562067
break;
@@ -2173,14 +2184,37 @@ static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field
21732184
value = wacom_offset_rotation(input, usage, value, 1, 2);
21742185
}
21752186
else if (field->flags & HID_MAIN_ITEM_RELATIVE) {
2176-
/* We must invert the sign for vertical
2177-
* relative scrolling. Clockwise rotation
2178-
* produces positive values from HW, but
2179-
* userspace treats positive REL_WHEEL as a
2180-
* scroll *up*!
2181-
*/
2182-
int hires_value = -value * 120 / usage->resolution_multiplier;
2183-
int *ring_value = &wacom_wac->hid_data.ring_value;
2187+
int hires_value = value * 120 / usage->resolution_multiplier;
2188+
int *ring_value;
2189+
int lowres_code;
2190+
2191+
if (usage->code == REL_WHEEL_HI_RES) {
2192+
/* We must invert the sign for vertical
2193+
* relative scrolling. Clockwise
2194+
* rotation produces positive values
2195+
* from HW, but userspace treats
2196+
* positive REL_WHEEL as a scroll *up*!
2197+
*/
2198+
hires_value = -hires_value;
2199+
ring_value = &wacom_wac->hid_data.ring_value;
2200+
lowres_code = REL_WHEEL;
2201+
}
2202+
else if (usage->code == REL_HWHEEL_HI_RES) {
2203+
/* No need to invert the sign for
2204+
* horizontal relative scrolling.
2205+
* Clockwise rotation produces positive
2206+
* values from HW and userspace treats
2207+
* positive REL_HWHEEL as a scroll
2208+
* right.
2209+
*/
2210+
ring_value = &wacom_wac->hid_data.ring2_value;
2211+
lowres_code = REL_HWHEEL;
2212+
}
2213+
else {
2214+
hid_err(wacom->hdev, "unrecognized relative wheel with code %d\n",
2215+
usage->code);
2216+
break;
2217+
}
21842218

21852219
value = hires_value;
21862220
*ring_value += hires_value;
@@ -2191,7 +2225,7 @@ static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field
21912225
if (*ring_value >= 120 || *ring_value <= -120) {
21922226
int clicks = *ring_value / 120;
21932227

2194-
input_event(input, usage->type, REL_WHEEL, clicks);
2228+
input_event(input, usage->type, lowres_code, clicks);
21952229
*ring_value -= clicks * 120;
21962230
}
21972231
}

drivers/hid/wacom_wac.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ struct hid_data {
313313
int height;
314314
int id;
315315
int ring_value;
316+
int ring2_value;
316317
int cc_report;
317318
int cc_index;
318319
int cc_value_index;
@@ -356,6 +357,8 @@ struct wacom_wac {
356357
int num_contacts_left;
357358
u8 bt_features;
358359
u8 bt_high_speed;
360+
u8 absring_count;
361+
u8 relring_count;
359362
int mode_report;
360363
int mode_value;
361364
struct hid_data hid_data;

0 commit comments

Comments
 (0)