WIP FPC-III support
[linux/fpc-iii.git] / drivers / iio / imu / inv_icm42600 / inv_icm42600_timestamp.h
blob4e4f331d4fe4b899f84ff586192e1019181b4795
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Copyright (C) 2020 Invensense, Inc.
4 */
6 #ifndef INV_ICM42600_TIMESTAMP_H_
7 #define INV_ICM42600_TIMESTAMP_H_
9 #include <linux/kernel.h>
11 struct inv_icm42600_state;
13 /**
14 * struct inv_icm42600_timestamp_interval - timestamps interval
15 * @lo: interval lower bound
16 * @up: interval upper bound
18 struct inv_icm42600_timestamp_interval {
19 int64_t lo;
20 int64_t up;
23 /**
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 {
30 uint32_t val;
31 size_t idx;
32 uint32_t values[32];
35 /**
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;
46 int64_t timestamp;
47 uint32_t mult;
48 uint32_t new_mult;
49 uint32_t period;
50 struct inv_icm42600_timestamp_acc chip_period;
53 void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts,
54 uint32_t period);
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);
65 static inline int64_t
66 inv_icm42600_timestamp_pop(struct inv_icm42600_timestamp *ts)
68 ts->timestamp += ts->period;
69 return ts->timestamp;
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);
76 static inline void
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;
82 ts->timestamp = 0;
85 #endif