Skip to contentSkip to conversation

usb: gadget: f_hid: allow setting different interval for each speed

PATCH Superseded Arthur Crépin Leblond 1 participant 1 message Aug 4 USB

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 usb: gadget: f_hid: allow setting different interval for each speed

The HID polling interval unit depends on the USB speed.

- Full speed: the units are in milliseconds
- High/Super speed: the units are in micro-frames of 0.125ms

Exposing directly the bInterval means that the user needs to know which speed is currently in use and has to convert it accordingly.

The solution is to expose the interval for each speed:
- interval_fs: bInterval for full-speed
- interval_hs: bInterval for high-speed
- interval_ss: bInterval for super-speed
- interval: legacy attribute that takes precedence over the per-speed
attributes and sets the same bInterval for each speed.

---
Changes in v3:
- Use sysfs_emit
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Expose a specific interval attribute per USB speed
- Use a define for the default values
- Update ABI documentation
- Link to v1: https://patch.msgid.link/[email protected]

---
 Documentation/ABI/testing/configfs-usb-gadget-hid |  18 ++
 drivers/usb/gadget/function/f_hid.c               | 193 +++++++++++++---------
 drivers/usb/gadget/function/u_hid.h               |   9 +-
 3 files changed, 143 insertions(+), 77 deletions(-)
Documentation/ABI/testing/configfs-usb-gadget-hid +18 -0
index 748705c4cb58..a81f5b527b59 100644
@@ -11,3 +11,21 @@ Description:
 		report_length	HID report length
 		subclass	HID device subclass to use
 		=============	============================================
+
+What:		/config/usb-gadget/gadget/functions/hid.name
+Date:		Jul 2026
+KernelVersion:	7.3
+Description:
+		The attributes:
+
+		=============	============================================
+		interval	HID endpoint bInterval for all speeds; if
+				set, it takes precedence over the
+				per-speed attributes below
+		interval_fs	HID endpoint bInterval for full-speed
+				(in milliseconds, default: 10)
+		interval_hs	HID endpoint bInterval for high-speed
+				(in 125 us units, default: 4)
+		interval_ss	HID endpoint bInterval for super-speed
+				(in 125 us units, default: 4)
+		=============	============================================
drivers/usb/gadget/function/f_hid.c +117 -76

274 lines not on this page · raw message

drivers/usb/gadget/function/u_hid.h +8 -1
index a9ed9720caee..e666cd9968eb 100644
@@ -15,6 +15,11 @@
 
 #include <linux/usb/composite.h>
 
+struct f_hid_opt_interval {
+	unsigned char value;
+	bool user_set;
+};
+
 struct f_hid_opts {
 	struct usb_function_instance	func_inst;
 	int				minor;
@@ -26,7 +31,9 @@ struct f_hid_opts {
 	unsigned char			*report_desc;
 	bool				report_desc_alloc;
 	unsigned char			interval;
-	bool				interval_user_set;
+	struct f_hid_opt_interval	interval_fs;
+	struct f_hid_opt_interval	interval_hs;
+	struct f_hid_opt_interval	interval_ss;
 
 	/*
 	 * Protect the data form concurrent access by read/write