[PATCH v5 09/13] HID: haptic: Handle list reports separately and make auto trigger optional
From: Rong Zhang
Date: Sun Nov 29 2026 - 12:58:02 EST
The Waveform List and Duration List collections are read-only and
inherently different from the Auto Trigger freture, which is read-write.
The latter may use a dedicated report or even missing [1] on some device
due to the difference.
Handle list reports separately to decouple them from the auto trigger
report, so that the latter becomes optional.
According to [1][2], Waveform Vendor Page and ID shall be declared
within the Waveform List. The requirement is now enforced to
intentionally ignore malformed Vendor Page and ID and further simplify
the code to make it more readable.
Also adopt the newly introduced HID_OD_RANGE macro to get rid of mixed
if-else and switch statements.
Link: https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/input-haptics-implementation-guide [1]
Link: https://usb.org/sites/default/files/hutrr63b_-_haptics_page_redline_0.pdf [2]
Signed-off-by: Rong Zhang <i@xxxxxxxx>
---
drivers/hid/hid-haptic.c | 134 ++++++++++++++++++++++++++++++++---------------
drivers/hid/hid-haptic.h | 2 +
2 files changed, 93 insertions(+), 43 deletions(-)
diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c
index 3edda5d6018b..84b35ec8365a 100644
--- a/drivers/hid/hid-haptic.c
+++ b/drivers/hid/hid-haptic.c
@@ -8,9 +8,11 @@
#define pr_fmt(fmt) "hid-haptic: " fmt
#define dev_fmt pr_fmt
+#include <linux/bitmap.h>
#include <linux/err.h>
#include <linux/input/mt.h>
#include <linux/module.h>
+#include <linux/types.h>
#include "hid-haptic.h"
@@ -19,26 +21,33 @@ static void __hid_haptic_feature_mapping(struct hid_device *hdev, struct hid_hap
{
u16 usage_hid;
- if (usage->hid == HID_HP_AUTOTRIGGER) {
+ switch (usage->hid) {
+ case HID_HP_AUTOTRIGGER:
if (usage->usage_index >= field->report_count) {
hid_err(hdev, "HID_HP_AUTOTRIGGER out of range\n");
return;
}
haptic->auto_trigger_report = field->report;
- } else if ((usage->hid & HID_USAGE_PAGE) == HID_UP_ORDINAL) {
+ break;
+ case HID_OD_RANGE:
usage_hid = usage->hid & HID_USAGE;
switch (field->logical) {
case HID_HP_WAVEFORMLIST:
+ haptic->waveform_list_report = field->report;
if (usage_hid > haptic->max_waveform_id)
haptic->max_waveform_id = usage_hid;
break;
case HID_HP_DURATIONLIST:
+ haptic->duration_list_report = field->report;
if (usage_hid > haptic->max_duration_id)
haptic->max_duration_id = usage_hid;
break;
default:
break;
}
+ break;
+ default:
+ break;
}
}
@@ -80,53 +89,69 @@ static bool __hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic,
return false;
}
-static void parse_auto_trigger_field(struct hid_haptic_device *haptic,
- struct hid_field *field)
+static void parse_waveform_list(struct hid_haptic_device *haptic, struct hid_field *field)
{
int count = field->report_count;
int n;
u16 usage_hid;
+ if (field->logical != HID_HP_WAVEFORMLIST)
+ return;
+
for (n = 0; n < count; n++) {
- switch (field->usage[n].hid & HID_USAGE_PAGE) {
- case HID_UP_ORDINAL:
+ switch (field->usage[n].hid) {
+ case HID_OD_RANGE:
usage_hid = field->usage[n].hid & HID_USAGE;
- switch (field->logical) {
- case HID_HP_WAVEFORMLIST:
- haptic->hid_usage_map[usage_hid] = field->value[n];
- if (field->value[n] ==
- (HID_HP_WAVEFORMPRESS & HID_USAGE)) {
- haptic->press_ordinal = usage_hid;
- } else if (field->value[n] ==
- (HID_HP_WAVEFORMRELEASE & HID_USAGE)) {
- haptic->release_ordinal = usage_hid;
- }
- break;
- case HID_HP_DURATIONLIST:
- haptic->duration_map[usage_hid] =
- field->value[n];
- break;
- default:
- break;
- }
+ haptic->hid_usage_map[usage_hid] = field->value[n];
+ if (field->value[n] == (HID_HP_WAVEFORMPRESS & HID_USAGE))
+ haptic->press_ordinal = usage_hid;
+ else if (field->value[n] == (HID_HP_WAVEFORMRELEASE & HID_USAGE))
+ haptic->release_ordinal = usage_hid;
break;
- case HID_UP_HAPTIC:
- switch (field->usage[n].hid) {
- case HID_HP_AUTOTRIGGER:
- haptic->default_auto_trigger = field->value[n];
- break;
- case HID_HP_WAVEFORMVENDORID:
- haptic->vendor_id = field->value[n];
- break;
- case HID_HP_WAVEFORMVENDORPAGE:
- haptic->vendor_page = field->value[n];
- break;
- default:
- break;
- }
+ case HID_HP_WAVEFORMVENDORID:
+ haptic->vendor_id = field->value[n];
+ break;
+ case HID_HP_WAVEFORMVENDORPAGE:
+ haptic->vendor_page = field->value[n];
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+static void parse_duration_list(struct hid_haptic_device *haptic, struct hid_field *field)
+{
+ int count = field->report_count;
+ int n;
+ u16 usage_hid;
+
+ if (field->logical != HID_HP_DURATIONLIST)
+ return;
+
+ for (n = 0; n < count; n++) {
+ switch (field->usage[n].hid) {
+ case HID_OD_RANGE:
+ usage_hid = field->usage[n].hid & HID_USAGE;
+ haptic->duration_map[usage_hid] = field->value[n];
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+static void parse_auto_trigger_field(struct hid_haptic_device *haptic, struct hid_field *field)
+{
+ int count = field->report_count;
+ int n;
+
+ for (n = 0; n < count; n++) {
+ switch (field->usage[n].hid) {
+ case HID_HP_AUTOTRIGGER:
+ haptic->default_auto_trigger = field->value[n];
break;
default:
- /* Should not really happen */
break;
}
}
@@ -194,6 +219,9 @@ static void switch_mode(struct hid_device *hdev, struct hid_haptic_device *hapti
s32 value;
int i, j;
+ if (!rep)
+ return;
+
if (mode == HID_HAPTIC_MODE_HOST)
value = HID_HAPTIC_ORDINAL_WAVEFORMSTOP;
else
@@ -387,11 +415,26 @@ static void hid_haptic_destroy(struct ff_device *ff)
static void hid_haptic_get_reports(struct hid_device *hdev, struct hid_haptic_device *haptic)
{
+ DECLARE_BITMAP(usage_map, HID_MAX_IDS) = {};
+ int i;
+
+ __set_bit(haptic->waveform_list_report->id, usage_map);
+ __set_bit(haptic->duration_list_report->id, usage_map);
+ if (haptic->auto_trigger_report)
+ __set_bit(haptic->auto_trigger_report->id, usage_map);
+
hid_device_io_start(hdev);
- hid_hw_request(hdev, haptic->auto_trigger_report, HID_REQ_GET_REPORT);
+ /*
+ * The three collections/usages may share the same report, or use
+ * dedicated ones. Skip duplicate GET_REPORT requests.
+ */
+ for_each_set_bit(i, usage_map, HID_MAX_IDS) {
+ hid_hw_request(hdev, hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[i],
+ HID_REQ_GET_REPORT);
+ hid_hw_wait(hdev);
+ }
- hid_hw_wait(hdev);
hid_device_io_stop(hdev);
}
@@ -433,7 +476,11 @@ static int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *ha
hid_haptic_get_reports(hdev, haptic);
- for (r = 0; r < haptic->auto_trigger_report->maxfield; r++)
+ for (r = 0; r < haptic->waveform_list_report->maxfield; r++)
+ parse_waveform_list(haptic, haptic->waveform_list_report->field[r]);
+ for (r = 0; r < haptic->duration_list_report->maxfield; r++)
+ parse_duration_list(haptic, haptic->duration_list_report->field[r]);
+ for (r = 0; haptic->auto_trigger_report && r < haptic->auto_trigger_report->maxfield; r++)
parse_auto_trigger_field(haptic, haptic->auto_trigger_report->field[r]);
haptic->input_dev = dev;
@@ -519,7 +566,8 @@ static int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *ha
static int hid_haptic_check_prerequisites(struct hid_device *hdev,
struct hid_haptic_device *haptic, struct hid_input *hi)
{
- if (!haptic->auto_trigger_report || !haptic->manual_trigger_report)
+ if (!haptic->waveform_list_report || !haptic->duration_list_report ||
+ !haptic->manual_trigger_report)
return -ENOENT;
if (IS_ERR_OR_NULL(haptic->input_dev))
diff --git a/drivers/hid/hid-haptic.h b/drivers/hid/hid-haptic.h
index 836520bf8dc7..ad2aa267677f 100644
--- a/drivers/hid/hid-haptic.h
+++ b/drivers/hid/hid-haptic.h
@@ -34,6 +34,8 @@ struct hid_haptic_effect_node {
struct hid_haptic_device {
struct input_dev *input_dev;
struct hid_device *hdev;
+ struct hid_report *waveform_list_report;
+ struct hid_report *duration_list_report;
struct hid_report *auto_trigger_report;
struct mutex auto_trigger_mutex;
struct workqueue_struct *wq;
--
2.55.0