[PATCH v6 2/7] platform/chrome: cros_ec_sensorhub: Reset TS filter on EC/AP time mismatch

From: Satyam Gupta

Date: Thu Oct 29 2026 - 05:29:23 EST


The timestamp filter history is only emptied when no interrupt happened
for TS_HISTORY_BORED_US of EC time. After a long gap without events, for
instance across suspend, b may be unwrapped to the wrong overflow period
and appear to have advanced very little, while the AP time advanced by
the whole gap. The filter then keeps a history that no longer matches
the offset between the EC and the AP, and predicts timestamps off by up
to an overflow period until that history is replaced.

Also empty the filter when the EC time and the AP time elapsed between
two interrupts differ by more than TS_HISTORY_BORED_US.

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

diff --git a/drivers/platform/chrome/cros_ec_sensorhub_ring.c b/drivers/platform/chrome/cros_ec_sensorhub_ring.c
index 7eb8841..076a65a 100644
--- a/drivers/platform/chrome/cros_ec_sensorhub_ring.c
+++ b/drivers/platform/chrome/cros_ec_sensorhub_ring.c
@@ -294,6 +294,14 @@ cros_ec_sensor_ring_ts_filter_update(struct cros_ec_sensors_ts_filter_state
if (-dx > TS_HISTORY_BORED_US)
state->history_len = 0;

+ /*
+ * Also empty it if the EC and the AP disagree on the elapsed time
+ * (dy, in ns), for instance when b was unwrapped to the wrong
+ * overflow period after a long gap without events.
+ */
+ if (abs(dy) > TS_HISTORY_BORED_US * NSEC_PER_USEC)
+ state->history_len = 0;
+
/* Move everything over, also update offset to all absolute coords .*/
for (i = state->history_len - 1; i >= 1; i--) {
state->x_history[i] = state->x_history[i - 1] + dx;
--
2.56.0.307.g5fe7bd680c-goog