Skip to content

Commit fd8d135

Browse files
alistair23bentiss
authored andcommitted
HID: quirks: Allow inverting the absolute X/Y values
Add a HID_QUIRK_X_INVERT/HID_QUIRK_Y_INVERT quirk that can be used to invert the X/Y values. Signed-off-by: Alistair Francis <alistair@alistair23.me> [bentiss: silence checkpatch warning] Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Link: https://lore.kernel.org/r/20211208124045.61815-2-alistair@alistair23.me
1 parent 9ea1b35 commit fd8d135

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

drivers/hid/hid-input.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,12 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
13291329

13301330
input = field->hidinput->input;
13311331

1332+
if (usage->type == EV_ABS &&
1333+
(((*quirks & HID_QUIRK_X_INVERT) && usage->code == ABS_X) ||
1334+
((*quirks & HID_QUIRK_Y_INVERT) && usage->code == ABS_Y))) {
1335+
value = field->logical_maximum - value;
1336+
}
1337+
13321338
if (usage->hat_min < usage->hat_max || usage->hat_dir) {
13331339
int hat_dir = usage->hat_dir;
13341340
if (!hat_dir)

include/linux/hid.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ struct hid_item {
359359
/* BIT(9) reserved for backward compatibility, was NO_INIT_INPUT_REPORTS */
360360
#define HID_QUIRK_ALWAYS_POLL BIT(10)
361361
#define HID_QUIRK_INPUT_PER_APP BIT(11)
362+
#define HID_QUIRK_X_INVERT BIT(12)
363+
#define HID_QUIRK_Y_INVERT BIT(13)
362364
#define HID_QUIRK_SKIP_OUTPUT_REPORTS BIT(16)
363365
#define HID_QUIRK_SKIP_OUTPUT_REPORT_ID BIT(17)
364366
#define HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP BIT(18)

0 commit comments

Comments
 (0)