mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] HID: sensor-hub: Fix report 17 interval size on Chicony 04f2:b872
@ 2026-12-03 15:38 Shan Rizvi
  0 siblings, 0 replies; only message in thread
From: Shan Rizvi @ 2026-12-03 15:38 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, Jonathan Cameron, Srinivas Pandruvada
  Cc: linux-input, linux-iio, linux-kernel, Chia-Lin Kao, Shan Rizvi, stable

On the Chicony HP 5MP Camera sensor hub (04f2:b872, bcdDevice 0x1020,
HP OmniBook X Flip 16 8EA2, BIOS F.07), probing the secondary proximity
sensor (feature report 17) via iio_info or iio-sensor-proxy stalls
runtime PM resume for hours.

All byte offsets below include the leading report ID at byte 0. Report
17 declares Report Interval (usage 0x030e) and Minimum Report Interval
(usage 0x0304) as 32-bit fields for a 122-byte report. On the wire,
GET_REPORT returns 120 bytes: a 16-bit Report Interval at bytes 6..7
followed immediately by the 32-bit Minimum Report Interval (100 ms) at
bytes 8..11 and the remaining fields, shifting every subsequent field
left by two bytes (including Friendly Name and Persistent Unique ID):

  parsed at declared offsets (bytes 26..57): "P AI SENSOR"
  actual wire layout         (bytes 24..55): "HP AI SENSOR"

Because hid-sensor-hub parses Report Interval as 32 bits, the default
wire bytes (d0 07 64 00) decode as 6,555,600 ms instead of 2000 ms,
causing in_proximity0_sampling_frequency to read 0.000100 and stalling
hid-sensor-trigger's runtime PM resume in
msleep_interruptible(poll_value * 2) for ~3.64 hours. On the write path,
hid-sensor-hub likewise constructs a 122-byte SET_REPORT with every
field after Report Interval shifted right by two bytes. Because this
device exposes working ALS (report 10) and primary proximity (report 1)
sensors, adding 04f2:b872 to hid_ignore_list would regress working
sensors.

Fix report 17's Report Size (32 -> 16) and Logical Maximum
(0x7fffffff -> 0x0000ffff) in-place in sensor_hub_report_fixup(),
matching the 1846-byte descriptor and the 18-byte item sequence at
offset 1553.

Tested on kernel 7.2.15 with stock hid-sensor-trigger:
in_proximity0_sampling_frequency reads 0.500000 and round-trips across
10, 1, and 0.5 Hz; raw HIDIOCGFEATURE dumps confirm SET_REPORT updates
bytes 6..7 without altering trailing fields; warm reads of
in_proximity0_raw return a live value (~212 ms) without stalling
runtime PM resume. After runtime autosuspend, a raw read can still hit
the pre-existing 5 s completion timeout in
sensor_hub_input_attr_get_raw_value() (returning 0), which is a
separate issue not addressed by this patch. Primary proximity and ALS
continue working.

Link: https://lore.kernel.org/r/179591783777.39.15448655394533903125@rizvi.nu
Cc: stable@vger.kernel.org
Signed-off-by: Shan Rizvi <shan@rizvi.nu>
---
Notes:
- Based on hid.git for-next; runtime-tested on 7.2.15 against stock
  hid-sensor-trigger.
- In the linked thread, Srinivas noted he plans to send a generic
  hid-sensor-trigger poll-interval clamp. Even with trigger-side
  clamping, report 17 still needs this descriptor fixup so GET_REPORT
  and SET_REPORT field offsets align.
- Kept in-kernel in sensor_hub_report_fixup() rather than HID-BPF
  because probing this sensor can stall runtime PM resume for hours on
  systems without udev-hid-bpf installed.
 drivers/hid/hid-ids.h        |  1 +
 drivers/hid/hid-sensor-hub.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index f841667..a6d84a7 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -349,6 +349,7 @@
 #define USB_DEVICE_ID_CHICONY_HP_5MP_CAMERA	0xb824
 #define USB_DEVICE_ID_CHICONY_HP_5MP_CAMERA2	0xb82c
 #define USB_DEVICE_ID_CHICONY_HP_5MP_CAMERA3	0xb882
+#define USB_DEVICE_ID_CHICONY_HP_5MP_CAMERA4	0xb872
 
 #define USB_VENDOR_ID_CHUNGHWAT		0x2247
 #define USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH	0x0001
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 2a7f247..8fdee5a 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -674,6 +674,34 @@ static const __u8 *sensor_hub_report_fixup(struct hid_device *hdev, __u8 *rdesc,
 		rdesc[917] = rdesc[938] = rdesc[959] = 0xff;
 	}
 
+	/*
+	 * Chicony HP 5MP Camera (04f2:b872) declares report 17's Report
+	 * Interval (usage 0x030e) as 32-bit, but firmware sends and expects
+	 * 16 bits (119-byte feature payload instead of 121). Fix Report Size
+	 * and Logical Maximum so report 17 matches the wire layout.
+	 */
+	if (hdev->vendor == USB_VENDOR_ID_CHICONY &&
+	    hdev->product == USB_DEVICE_ID_CHICONY_HP_5MP_CAMERA4 &&
+	    *rsize == 1846) {
+		static const __u8 report17_interval[] = {
+			0x0a, 0x0e, 0x03,             /* Usage (Report Interval) */
+			0x15, 0x00,                   /* Logical Minimum (0) */
+			0x27, 0xff, 0xff, 0xff, 0x7f, /* Logical Maximum (0x7fffffff) */
+			0x75, 0x20,                   /* Report Size (32) */
+			0x95, 0x01,                   /* Report Count (1) */
+			0x55, 0x00,                   /* Unit Exponent (0) */
+			0xb1, 0x02,                   /* Feature (Data,Var,Abs) */
+		};
+
+		if (!memcmp(&rdesc[1553], report17_interval,
+			    sizeof(report17_interval))) {
+			hid_info(hdev, "fixing up Chicony HP 5MP Camera report 17 interval size\n");
+			rdesc[1561] = 0x00;
+			rdesc[1562] = 0x00;
+			rdesc[1564] = 0x10;
+		}
+	}
+
 	return rdesc;
 }
 
base-commit: 47d0d5ce3cfca63a04eabcbeef7086d06240ff97
-- 
2.56.0

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-03 15:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 15:38 [PATCH] HID: sensor-hub: Fix report 17 interval size on Chicony 04f2:b872 Shan Rizvi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®