]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
HID: input: map HID_GD_Z to ABS_DISTANCE for stylus/pen
authorPing Cheng <pinglinux@gmail.com>
Mon, 27 Oct 2025 20:37:42 +0000 (13:37 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Jan 2026 12:09:45 +0000 (13:09 +0100)
commit 7953794f741e94d30df9dafaaa4c031c85b891d6 upstream.

HID_GD_Z is mapped to ABS_Z for stylus and pen in hid-input.c. But HID_GD_Z
should be used to report ABS_DISTANCE for stylus and pen as described at:
Documentation/input/event-codes.rst#n226

* ABS_DISTANCE:

  - Used to describe the distance of a tool from an interaction surface. This
    event should only be emitted while the tool is hovering, meaning in close
    proximity of the device and while the value of the BTN_TOUCH code is 0. If
    the input device may be used freely in three dimensions, consider ABS_Z
    instead.
  - BTN_TOOL_<name> should be set to 1 when the tool comes into detectable
    proximity and set to 0 when the tool leaves detectable proximity.
    BTN_TOOL_<name> signals the type of tool that is currently detected by the
    hardware and is otherwise independent of ABS_DISTANCE and/or BTN_TOUCH.

This patch makes the correct mapping. The ABS_DISTANCE is currently not mapped
by any HID usage in hid-generic driver.

Signed-off-by: Ping Cheng <ping.cheng@wacom.com>
Cc: stable@kernel.org
Signed-off-by: Jiri Kosina <jkosina@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hid/hid-input.c

index 0ae959e54462b4bc74ee26d808034e65aed74869..d03a447dbe6b8fd702a0e9c9b339b6fe4de3c357 100644 (file)
@@ -752,7 +752,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
 
                switch (usage->hid) {
                /* These usage IDs map directly to the usage codes. */
-               case HID_GD_X: case HID_GD_Y: case HID_GD_Z:
+               case HID_GD_X: case HID_GD_Y:
                case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ:
                        if (field->flags & HID_MAIN_ITEM_RELATIVE)
                                map_rel(usage->hid & 0xf);
@@ -760,6 +760,22 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
                                map_abs_clear(usage->hid & 0xf);
                        break;
 
+               case HID_GD_Z:
+                       /* HID_GD_Z is mapped to ABS_DISTANCE for stylus/pen */
+                       if (field->flags & HID_MAIN_ITEM_RELATIVE) {
+                               map_rel(usage->hid & 0xf);
+                       } else {
+                               if (field->application == HID_DG_PEN ||
+                                   field->physical == HID_DG_PEN ||
+                                   field->logical == HID_DG_STYLUS ||
+                                   field->physical == HID_DG_STYLUS ||
+                                   field->application == HID_DG_DIGITIZER)
+                                       map_abs_clear(ABS_DISTANCE);
+                               else
+                                       map_abs_clear(usage->hid & 0xf);
+                       }
+                       break;
+
                case HID_GD_WHEEL:
                        if (field->flags & HID_MAIN_ITEM_RELATIVE) {
                                set_bit(REL_WHEEL, input->relbit);