[PATCH v6 5/7] platform/chrome: cros_ec_sensorhub: Reset TS filter on ODR or mode changes

From: Satyam Gupta

Date: Thu Oct 29 2026 - 05:33:28 EST


From: Scott Collyer <scollyer@xxxxxxxxxx>

When a sensor changes Output Data Rate (ODR), or switches between active
streaming and low-frequency batching, the interval between EC interrupts
changes abruptly. Slopes measured over very different intervals then get
mixed in the same median filter history.

Reset the timestamp filter history when the interval between interrupts
changes by more than 10x compared to the previous interval.

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

diff --git a/drivers/platform/chrome/cros_ec_sensorhub_ring.c b/drivers/platform/chrome/cros_ec_sensorhub_ring.c
index 46f44c6..cec33a7 100644
--- a/drivers/platform/chrome/cros_ec_sensorhub_ring.c
+++ b/drivers/platform/chrome/cros_ec_sensorhub_ring.c
@@ -304,6 +304,20 @@ 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 interval between
+ * interrupts changes by more than 10x in either direction, reset the
+ * filter history to avoid mixing slopes measured over very different
+ * intervals.
+ */
+ if (state->history_len > 1) {
+ s64 prev_dx = -state->x_history[1];
+
+ if (prev_dx > 0 && (-dx > 10 * prev_dx || prev_dx > 10 * -dx))
+ state->history_len = 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.307.g5fe7bd680c-goog