1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2020 Invensense, Inc.
6 #ifndef INV_ICM42600_TIMESTAMP_H_
7 #define INV_ICM42600_TIMESTAMP_H_
9 #include <linux/kernel.h>
11 struct inv_icm42600_state
;
14 * struct inv_icm42600_timestamp_interval - timestamps interval
15 * @lo: interval lower bound
16 * @up: interval upper bound
18 struct inv_icm42600_timestamp_interval
{
24 * struct inv_icm42600_timestamp_acc - accumulator for computing an estimation
25 * @val: current estimation of the value, the mean of all values
26 * @idx: current index of the next free place in values table
27 * @values: table of all measured values, use for computing the mean
29 struct inv_icm42600_timestamp_acc
{
36 * struct inv_icm42600_timestamp - timestamp management states
37 * @it: interrupts interval timestamps
38 * @timestamp: store last timestamp for computing next data timestamp
39 * @mult: current internal period multiplier
40 * @new_mult: new set internal period multiplier (not yet effective)
41 * @period: measured current period of the sensor
42 * @chip_period: accumulator for computing internal chip period
44 struct inv_icm42600_timestamp
{
45 struct inv_icm42600_timestamp_interval it
;
50 struct inv_icm42600_timestamp_acc chip_period
;
53 void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp
*ts
,
56 int inv_icm42600_timestamp_setup(struct inv_icm42600_state
*st
);
58 int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp
*ts
,
59 uint32_t period
, bool fifo
);
61 void inv_icm42600_timestamp_interrupt(struct inv_icm42600_timestamp
*ts
,
62 uint32_t fifo_period
, size_t fifo_nb
,
63 size_t sensor_nb
, int64_t timestamp
);
66 inv_icm42600_timestamp_pop(struct inv_icm42600_timestamp
*ts
)
68 ts
->timestamp
+= ts
->period
;
72 void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp
*ts
,
73 uint32_t fifo_period
, size_t fifo_nb
,
74 unsigned int fifo_no
);
77 inv_icm42600_timestamp_reset(struct inv_icm42600_timestamp
*ts
)
79 const struct inv_icm42600_timestamp_interval interval_init
= {0LL, 0LL};
81 ts
->it
= interval_init
;