[PATCH v5 4/6] platform/chrome: cros_ec_sensorhub: Reset TS filter on ODR or mode changes

From: Satyam Gupta

Date: Wed Oct 14 2026 - 03:44:54 EST


From: Scott Collyer <scollyer@xxxxxxxxxx>

Detect Output Data Rate (ODR) or mode transitions (such as switching
between active streaming and low-frequency batching) where the time
delta (dx) between consecutive interrupts changes by more than 10x, and
reset the timestamp filter history. This prevents mixing noisy active
streaming samples with larger batched intervals in the median filter.

Signed-off-by: Scott Collyer <scollyer@xxxxxxxxxx>
Signed-off-by: Satyam Gupta <sgsatyam@xxxxxxxxxx>
---
drivers/platform/chrome/cros_ec_sensorhub_ring.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_sensorhub_ring.c b/drivers/platform/chrome/cros_ec_sensorhub_ring.c
index ea70847c8792..4d814e2d7297 100644
--- a/drivers/platform/chrome/cros_ec_sensorhub_ring.c
+++ b/drivers/platform/chrome/cros_ec_sensorhub_ring.c
@@ -280,6 +280,21 @@ cros_ec_sensor_ring_ts_filter_update(struct cros_ec_sensors_ts_filter_state
*/
m = clamp(m, -MAX_M, MAX_M);

+ /*
+ * Detect ODR (Output Data Rate) or Mode changes (e.g., transition from
+ * active streaming to low-frequency batching). If the time delta (dx)
+ * changes by more than 10x in either direction, reset the filter history
+ * to prevent mixing noisy active samples with batching samples.
+ */
+ if (state->history_len > 1) {
+ s64 prev_dx = -state->x_history[1];
+
+ if (prev_dx > 0 && (abs(dx) > 10 * prev_dx || prev_dx > 10 * abs(dx))) {
+ state->history_len = 0;
+ m = 0;
+ }
+ }
+
/* Empty filter if we haven't seen any action in a while. */
if (-dx > TS_HISTORY_BORED_US)
state->history_len = 0;
--
2.56.0.385.gd3acb90ef8-goog