Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98ce0b82 authored by Mario Tesi's avatar Mario Tesi Committed by Gerrit - the friendly Code Review server
Browse files

drivers: iio: imu: Added HW timestamp rollover management

In case of continuous long run (over ~30 hours) manage HW
timestamp rollover.

Git-commit: d2962be976ed01f0176dc1e920172547f6aadbf0
Git-repo: https://github.com/STMicroelectronics/STMems_ASM330LHH_IIO_HAL_Driver.git


Signed-off-by: default avatarMario Tesi <mario.tesi@st.com>
(cherry picked from commit d2962be976ed01f0176dc1e920172547f6aadbf0).

Change-Id: Ia529ddaef67f12c31aea52a63c7702ad3a157bc0
Signed-off-by: default avatarPuneet Yatnal <puneet@codeaurora.org>
parent 5894aae4
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
#include <linux/slab.h>

#define ST_ASM330LHH_REVISION		"2.0.1"
#define ST_ASM330LHH_PATCH		"1"
#define ST_ASM330LHH_PATCH		"2"

#define ST_ASM330LHH_VERSION		"v"	\
	ST_ASM330LHH_REVISION			\
@@ -220,7 +220,10 @@ struct st_asm330lhh_hw {
	u8 enable_mask;

	s64 ts_offset;
	u32 hw_val;
	u32 hw_val_old;
	s64 hw_ts;
	s64 hw_ts_high;
	s64 delta_ts;
	s64 ts;
	s64 tsample;
+12 −5
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ static inline int st_asm330lhh_reset_hwts(struct st_asm330lhh_hw *hw)
	hw->ts_offset = hw->ts;
	hw->hw_ts_old = 0ull;
	hw->tsample = 0ull;
	hw->hw_ts_high = 0ull;
	hw->hw_val_old = 0ull;

	return hw->tf->write(hw->dev, ST_ASM330LHH_REG_TS2_ADDR, sizeof(data),
			     &data);
@@ -257,14 +259,12 @@ static int st_asm330lhh_read_fifo(struct st_asm330lhh_hw *hw)
	struct iio_dev *iio_dev;
	__le16 fifo_status;
	u16 fifo_depth;
	u32 val;
	int ts_processed = 0;
	s64 hw_ts = 0ull, delta_hw_ts, cpu_timestamp;

	ts_irq = hw->ts - hw->delta_ts;

	do
	{
	do {
		err = hw->tf->read(hw->dev, ST_ASM330LHH_REG_FIFO_DIFFL_ADDR,
				   sizeof(fifo_status), (u8 *)&fifo_status);
		if (err < 0)
@@ -289,8 +289,14 @@ static int st_asm330lhh_read_fifo(struct st_asm330lhh_hw *hw)
				tag = buf[i] >> 3;

				if (tag == ST_ASM330LHH_TS_TAG) {
					val = get_unaligned_le32(ptr);
					hw->hw_ts = val * ST_ASM330LHH_TS_DELTA_NS;
					hw->hw_val = get_unaligned_le32(ptr);

					/* check for timer rollover */
					if (hw->hw_val < hw->hw_val_old)
						hw->hw_ts_high++;
					hw->hw_ts =
					(hw->hw_val + (hw->hw_ts_high << 32))
						* ST_ASM330LHH_TS_DELTA_NS;
					ts_delta_hw_ts = hw->hw_ts - hw->hw_ts_old;
					hw_ts += ts_delta_hw_ts;
					ts_delta_offs =
@@ -301,6 +307,7 @@ static int st_asm330lhh_read_fifo(struct st_asm330lhh_hw *hw)

					ts_irq += (hw->hw_ts + ts_delta_offs);
					hw->hw_ts_old = hw->hw_ts;
					hw->hw_val_old = hw->hw_val;
					ts_processed++;

					if (!hw->tsample)