18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2020 Invensense, Inc.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef INV_ICM42600_H_
78c2ecf20Sopenharmony_ci#define INV_ICM42600_H_
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/bits.h>
108c2ecf20Sopenharmony_ci#include <linux/bitfield.h>
118c2ecf20Sopenharmony_ci#include <linux/regmap.h>
128c2ecf20Sopenharmony_ci#include <linux/mutex.h>
138c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h>
148c2ecf20Sopenharmony_ci#include <linux/pm.h>
158c2ecf20Sopenharmony_ci#include <linux/iio/iio.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "inv_icm42600_buffer.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cienum inv_icm42600_chip {
208c2ecf20Sopenharmony_ci	INV_CHIP_INVALID,
218c2ecf20Sopenharmony_ci	INV_CHIP_ICM42600,
228c2ecf20Sopenharmony_ci	INV_CHIP_ICM42602,
238c2ecf20Sopenharmony_ci	INV_CHIP_ICM42605,
248c2ecf20Sopenharmony_ci	INV_CHIP_ICM42622,
258c2ecf20Sopenharmony_ci	INV_CHIP_NB,
268c2ecf20Sopenharmony_ci};
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/* serial bus slew rates */
298c2ecf20Sopenharmony_cienum inv_icm42600_slew_rate {
308c2ecf20Sopenharmony_ci	INV_ICM42600_SLEW_RATE_20_60NS,
318c2ecf20Sopenharmony_ci	INV_ICM42600_SLEW_RATE_12_36NS,
328c2ecf20Sopenharmony_ci	INV_ICM42600_SLEW_RATE_6_18NS,
338c2ecf20Sopenharmony_ci	INV_ICM42600_SLEW_RATE_4_12NS,
348c2ecf20Sopenharmony_ci	INV_ICM42600_SLEW_RATE_2_6NS,
358c2ecf20Sopenharmony_ci	INV_ICM42600_SLEW_RATE_INF_2NS,
368c2ecf20Sopenharmony_ci};
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cienum inv_icm42600_sensor_mode {
398c2ecf20Sopenharmony_ci	INV_ICM42600_SENSOR_MODE_OFF,
408c2ecf20Sopenharmony_ci	INV_ICM42600_SENSOR_MODE_STANDBY,
418c2ecf20Sopenharmony_ci	INV_ICM42600_SENSOR_MODE_LOW_POWER,
428c2ecf20Sopenharmony_ci	INV_ICM42600_SENSOR_MODE_LOW_NOISE,
438c2ecf20Sopenharmony_ci	INV_ICM42600_SENSOR_MODE_NB,
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci/* gyroscope fullscale values */
478c2ecf20Sopenharmony_cienum inv_icm42600_gyro_fs {
488c2ecf20Sopenharmony_ci	INV_ICM42600_GYRO_FS_2000DPS,
498c2ecf20Sopenharmony_ci	INV_ICM42600_GYRO_FS_1000DPS,
508c2ecf20Sopenharmony_ci	INV_ICM42600_GYRO_FS_500DPS,
518c2ecf20Sopenharmony_ci	INV_ICM42600_GYRO_FS_250DPS,
528c2ecf20Sopenharmony_ci	INV_ICM42600_GYRO_FS_125DPS,
538c2ecf20Sopenharmony_ci	INV_ICM42600_GYRO_FS_62_5DPS,
548c2ecf20Sopenharmony_ci	INV_ICM42600_GYRO_FS_31_25DPS,
558c2ecf20Sopenharmony_ci	INV_ICM42600_GYRO_FS_15_625DPS,
568c2ecf20Sopenharmony_ci	INV_ICM42600_GYRO_FS_NB,
578c2ecf20Sopenharmony_ci};
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/* accelerometer fullscale values */
608c2ecf20Sopenharmony_cienum inv_icm42600_accel_fs {
618c2ecf20Sopenharmony_ci	INV_ICM42600_ACCEL_FS_16G,
628c2ecf20Sopenharmony_ci	INV_ICM42600_ACCEL_FS_8G,
638c2ecf20Sopenharmony_ci	INV_ICM42600_ACCEL_FS_4G,
648c2ecf20Sopenharmony_ci	INV_ICM42600_ACCEL_FS_2G,
658c2ecf20Sopenharmony_ci	INV_ICM42600_ACCEL_FS_NB,
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/* ODR suffixed by LN or LP are Low-Noise or Low-Power mode only */
698c2ecf20Sopenharmony_cienum inv_icm42600_odr {
708c2ecf20Sopenharmony_ci	INV_ICM42600_ODR_8KHZ_LN = 3,
718c2ecf20Sopenharmony_ci	INV_ICM42600_ODR_4KHZ_LN,
728c2ecf20Sopenharmony_ci	INV_ICM42600_ODR_2KHZ_LN,
738c2ecf20Sopenharmony_ci	INV_ICM42600_ODR_1KHZ_LN,
748c2ecf20Sopenharmony_ci	INV_ICM42600_ODR_200HZ,
758c2ecf20Sopenharmony_ci	INV_ICM42600_ODR_100HZ,
768c2ecf20Sopenharmony_ci	INV_ICM42600_ODR_50HZ,
778c2ecf20Sopenharmony_ci	INV_ICM42600_ODR_25HZ,
788c2ecf20Sopenharmony_ci	INV_ICM42600_ODR_12_5HZ,
798c2ecf20Sopenharmony_ci	INV_ICM42600_ODR_6_25HZ_LP,
808c2ecf20Sopenharmony_ci	INV_ICM42600_ODR_3_125HZ_LP,
818c2ecf20Sopenharmony_ci	INV_ICM42600_ODR_1_5625HZ_LP,
828c2ecf20Sopenharmony_ci	INV_ICM42600_ODR_500HZ,
838c2ecf20Sopenharmony_ci	INV_ICM42600_ODR_NB,
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cienum inv_icm42600_filter {
878c2ecf20Sopenharmony_ci	/* Low-Noise mode sensor data filter (3rd order filter by default) */
888c2ecf20Sopenharmony_ci	INV_ICM42600_FILTER_BW_ODR_DIV_2,
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	/* Low-Power mode sensor data filter (averaging) */
918c2ecf20Sopenharmony_ci	INV_ICM42600_FILTER_AVG_1X = 1,
928c2ecf20Sopenharmony_ci	INV_ICM42600_FILTER_AVG_16X = 6,
938c2ecf20Sopenharmony_ci};
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cistruct inv_icm42600_sensor_conf {
968c2ecf20Sopenharmony_ci	int mode;
978c2ecf20Sopenharmony_ci	int fs;
988c2ecf20Sopenharmony_ci	int odr;
998c2ecf20Sopenharmony_ci	int filter;
1008c2ecf20Sopenharmony_ci};
1018c2ecf20Sopenharmony_ci#define INV_ICM42600_SENSOR_CONF_INIT		{-1, -1, -1, -1}
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cistruct inv_icm42600_conf {
1048c2ecf20Sopenharmony_ci	struct inv_icm42600_sensor_conf gyro;
1058c2ecf20Sopenharmony_ci	struct inv_icm42600_sensor_conf accel;
1068c2ecf20Sopenharmony_ci	bool temp_en;
1078c2ecf20Sopenharmony_ci};
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cistruct inv_icm42600_suspended {
1108c2ecf20Sopenharmony_ci	enum inv_icm42600_sensor_mode gyro;
1118c2ecf20Sopenharmony_ci	enum inv_icm42600_sensor_mode accel;
1128c2ecf20Sopenharmony_ci	bool temp;
1138c2ecf20Sopenharmony_ci};
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/**
1168c2ecf20Sopenharmony_ci *  struct inv_icm42600_state - driver state variables
1178c2ecf20Sopenharmony_ci *  @lock:		lock for serializing multiple registers access.
1188c2ecf20Sopenharmony_ci *  @chip:		chip identifier.
1198c2ecf20Sopenharmony_ci *  @name:		chip name.
1208c2ecf20Sopenharmony_ci *  @map:		regmap pointer.
1218c2ecf20Sopenharmony_ci *  @vdd_supply:	VDD voltage regulator for the chip.
1228c2ecf20Sopenharmony_ci *  @vddio_supply:	I/O voltage regulator for the chip.
1238c2ecf20Sopenharmony_ci *  @orientation:	sensor chip orientation relative to main hardware.
1248c2ecf20Sopenharmony_ci *  @conf:		chip sensors configurations.
1258c2ecf20Sopenharmony_ci *  @suspended:		suspended sensors configuration.
1268c2ecf20Sopenharmony_ci *  @indio_gyro:	gyroscope IIO device.
1278c2ecf20Sopenharmony_ci *  @indio_accel:	accelerometer IIO device.
1288c2ecf20Sopenharmony_ci *  @buffer:		data transfer buffer aligned for DMA.
1298c2ecf20Sopenharmony_ci *  @fifo:		FIFO management structure.
1308c2ecf20Sopenharmony_ci *  @timestamp:		interrupt timestamps.
1318c2ecf20Sopenharmony_ci */
1328c2ecf20Sopenharmony_cistruct inv_icm42600_state {
1338c2ecf20Sopenharmony_ci	struct mutex lock;
1348c2ecf20Sopenharmony_ci	enum inv_icm42600_chip chip;
1358c2ecf20Sopenharmony_ci	const char *name;
1368c2ecf20Sopenharmony_ci	struct regmap *map;
1378c2ecf20Sopenharmony_ci	struct regulator *vdd_supply;
1388c2ecf20Sopenharmony_ci	struct regulator *vddio_supply;
1398c2ecf20Sopenharmony_ci	struct iio_mount_matrix orientation;
1408c2ecf20Sopenharmony_ci	struct inv_icm42600_conf conf;
1418c2ecf20Sopenharmony_ci	struct inv_icm42600_suspended suspended;
1428c2ecf20Sopenharmony_ci	struct iio_dev *indio_gyro;
1438c2ecf20Sopenharmony_ci	struct iio_dev *indio_accel;
1448c2ecf20Sopenharmony_ci	uint8_t buffer[2] ____cacheline_aligned;
1458c2ecf20Sopenharmony_ci	struct inv_icm42600_fifo fifo;
1468c2ecf20Sopenharmony_ci	struct {
1478c2ecf20Sopenharmony_ci		int64_t gyro;
1488c2ecf20Sopenharmony_ci		int64_t accel;
1498c2ecf20Sopenharmony_ci	} timestamp;
1508c2ecf20Sopenharmony_ci};
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/* Virtual register addresses: @bank on MSB (4 upper bits), @address on LSB */
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci/* Bank selection register, available in all banks */
1558c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_BANK_SEL			0x76
1568c2ecf20Sopenharmony_ci#define INV_ICM42600_BANK_SEL_MASK			GENMASK(2, 0)
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci/* User bank 0 (MSB 0x00) */
1598c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_DEVICE_CONFIG			0x0011
1608c2ecf20Sopenharmony_ci#define INV_ICM42600_DEVICE_CONFIG_SOFT_RESET		BIT(0)
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_DRIVE_CONFIG			0x0013
1638c2ecf20Sopenharmony_ci#define INV_ICM42600_DRIVE_CONFIG_I2C_MASK		GENMASK(5, 3)
1648c2ecf20Sopenharmony_ci#define INV_ICM42600_DRIVE_CONFIG_I2C(_rate)		\
1658c2ecf20Sopenharmony_ci		FIELD_PREP(INV_ICM42600_DRIVE_CONFIG_I2C_MASK, (_rate))
1668c2ecf20Sopenharmony_ci#define INV_ICM42600_DRIVE_CONFIG_SPI_MASK		GENMASK(2, 0)
1678c2ecf20Sopenharmony_ci#define INV_ICM42600_DRIVE_CONFIG_SPI(_rate)		\
1688c2ecf20Sopenharmony_ci		FIELD_PREP(INV_ICM42600_DRIVE_CONFIG_SPI_MASK, (_rate))
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_INT_CONFIG			0x0014
1718c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT2_LATCHED		BIT(5)
1728c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT2_PUSH_PULL		BIT(4)
1738c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT2_ACTIVE_HIGH	BIT(3)
1748c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT2_ACTIVE_LOW		0x00
1758c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT1_LATCHED		BIT(2)
1768c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT1_PUSH_PULL		BIT(1)
1778c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT1_ACTIVE_HIGH	BIT(0)
1788c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT1_ACTIVE_LOW		0x00
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_FIFO_CONFIG			0x0016
1818c2ecf20Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG_MASK			GENMASK(7, 6)
1828c2ecf20Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG_BYPASS			\
1838c2ecf20Sopenharmony_ci		FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 0)
1848c2ecf20Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG_STREAM			\
1858c2ecf20Sopenharmony_ci		FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 1)
1868c2ecf20Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG_STOP_ON_FULL		\
1878c2ecf20Sopenharmony_ci		FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 2)
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci/* all sensor data are 16 bits (2 registers wide) in big-endian */
1908c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_TEMP_DATA			0x001D
1918c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_ACCEL_DATA_X			0x001F
1928c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_ACCEL_DATA_Y			0x0021
1938c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_ACCEL_DATA_Z			0x0023
1948c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_GYRO_DATA_X			0x0025
1958c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_GYRO_DATA_Y			0x0027
1968c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_GYRO_DATA_Z			0x0029
1978c2ecf20Sopenharmony_ci#define INV_ICM42600_DATA_INVALID			-32768
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_INT_STATUS			0x002D
2008c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_STATUS_UI_FSYNC		BIT(6)
2018c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_STATUS_PLL_RDY			BIT(5)
2028c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_STATUS_RESET_DONE		BIT(4)
2038c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_STATUS_DATA_RDY		BIT(3)
2048c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_STATUS_FIFO_THS		BIT(2)
2058c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_STATUS_FIFO_FULL		BIT(1)
2068c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_STATUS_AGC_RDY			BIT(0)
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci/*
2098c2ecf20Sopenharmony_ci * FIFO access registers
2108c2ecf20Sopenharmony_ci * FIFO count is 16 bits (2 registers) big-endian
2118c2ecf20Sopenharmony_ci * FIFO data is a continuous read register to read FIFO content
2128c2ecf20Sopenharmony_ci */
2138c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_FIFO_COUNT			0x002E
2148c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_FIFO_DATA			0x0030
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_SIGNAL_PATH_RESET		0x004B
2178c2ecf20Sopenharmony_ci#define INV_ICM42600_SIGNAL_PATH_RESET_DMP_INIT_EN	BIT(6)
2188c2ecf20Sopenharmony_ci#define INV_ICM42600_SIGNAL_PATH_RESET_DMP_MEM_RESET	BIT(5)
2198c2ecf20Sopenharmony_ci#define INV_ICM42600_SIGNAL_PATH_RESET_RESET		BIT(3)
2208c2ecf20Sopenharmony_ci#define INV_ICM42600_SIGNAL_PATH_RESET_TMST_STROBE	BIT(2)
2218c2ecf20Sopenharmony_ci#define INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH	BIT(1)
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci/* default configuration: all data big-endian and fifo count in bytes */
2248c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_INTF_CONFIG0			0x004C
2258c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG0_FIFO_HOLD_LAST_DATA	BIT(7)
2268c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG0_FIFO_COUNT_REC	BIT(6)
2278c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG0_FIFO_COUNT_ENDIAN	BIT(5)
2288c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG0_SENSOR_DATA_ENDIAN	BIT(4)
2298c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK	GENMASK(1, 0)
2308c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_SPI_DIS	\
2318c2ecf20Sopenharmony_ci		FIELD_PREP(INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK, 2)
2328c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_I2C_DIS	\
2338c2ecf20Sopenharmony_ci		FIELD_PREP(INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK, 3)
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_INTF_CONFIG1			0x004D
2368c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG1_ACCEL_LP_CLK_RC	BIT(3)
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_PWR_MGMT0			0x004E
2398c2ecf20Sopenharmony_ci#define INV_ICM42600_PWR_MGMT0_TEMP_DIS			BIT(5)
2408c2ecf20Sopenharmony_ci#define INV_ICM42600_PWR_MGMT0_IDLE			BIT(4)
2418c2ecf20Sopenharmony_ci#define INV_ICM42600_PWR_MGMT0_GYRO(_mode)		\
2428c2ecf20Sopenharmony_ci		FIELD_PREP(GENMASK(3, 2), (_mode))
2438c2ecf20Sopenharmony_ci#define INV_ICM42600_PWR_MGMT0_ACCEL(_mode)		\
2448c2ecf20Sopenharmony_ci		FIELD_PREP(GENMASK(1, 0), (_mode))
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_GYRO_CONFIG0			0x004F
2478c2ecf20Sopenharmony_ci#define INV_ICM42600_GYRO_CONFIG0_FS(_fs)		\
2488c2ecf20Sopenharmony_ci		FIELD_PREP(GENMASK(7, 5), (_fs))
2498c2ecf20Sopenharmony_ci#define INV_ICM42600_GYRO_CONFIG0_ODR(_odr)		\
2508c2ecf20Sopenharmony_ci		FIELD_PREP(GENMASK(3, 0), (_odr))
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_ACCEL_CONFIG0			0x0050
2538c2ecf20Sopenharmony_ci#define INV_ICM42600_ACCEL_CONFIG0_FS(_fs)		\
2548c2ecf20Sopenharmony_ci		FIELD_PREP(GENMASK(7, 5), (_fs))
2558c2ecf20Sopenharmony_ci#define INV_ICM42600_ACCEL_CONFIG0_ODR(_odr)		\
2568c2ecf20Sopenharmony_ci		FIELD_PREP(GENMASK(3, 0), (_odr))
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_GYRO_ACCEL_CONFIG0		0x0052
2598c2ecf20Sopenharmony_ci#define INV_ICM42600_GYRO_ACCEL_CONFIG0_ACCEL_FILT(_f)	\
2608c2ecf20Sopenharmony_ci		FIELD_PREP(GENMASK(7, 4), (_f))
2618c2ecf20Sopenharmony_ci#define INV_ICM42600_GYRO_ACCEL_CONFIG0_GYRO_FILT(_f)	\
2628c2ecf20Sopenharmony_ci		FIELD_PREP(GENMASK(3, 0), (_f))
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_TMST_CONFIG			0x0054
2658c2ecf20Sopenharmony_ci#define INV_ICM42600_TMST_CONFIG_MASK			GENMASK(4, 0)
2668c2ecf20Sopenharmony_ci#define INV_ICM42600_TMST_CONFIG_TMST_TO_REGS_EN	BIT(4)
2678c2ecf20Sopenharmony_ci#define INV_ICM42600_TMST_CONFIG_TMST_RES_16US		BIT(3)
2688c2ecf20Sopenharmony_ci#define INV_ICM42600_TMST_CONFIG_TMST_DELTA_EN		BIT(2)
2698c2ecf20Sopenharmony_ci#define INV_ICM42600_TMST_CONFIG_TMST_FSYNC_EN		BIT(1)
2708c2ecf20Sopenharmony_ci#define INV_ICM42600_TMST_CONFIG_TMST_EN		BIT(0)
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_FIFO_CONFIG1			0x005F
2738c2ecf20Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG1_RESUME_PARTIAL_RD	BIT(6)
2748c2ecf20Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG1_WM_GT_TH		BIT(5)
2758c2ecf20Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG1_TMST_FSYNC_EN		BIT(3)
2768c2ecf20Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG1_TEMP_EN		BIT(2)
2778c2ecf20Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG1_GYRO_EN		BIT(1)
2788c2ecf20Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG1_ACCEL_EN		BIT(0)
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci/* FIFO watermark is 16 bits (2 registers wide) in little-endian */
2818c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_FIFO_WATERMARK			0x0060
2828c2ecf20Sopenharmony_ci#define INV_ICM42600_FIFO_WATERMARK_VAL(_wm)		\
2838c2ecf20Sopenharmony_ci		cpu_to_le16((_wm) & GENMASK(11, 0))
2848c2ecf20Sopenharmony_ci/* FIFO is 2048 bytes, let 12 samples for reading latency */
2858c2ecf20Sopenharmony_ci#define INV_ICM42600_FIFO_WATERMARK_MAX			(2048 - 12 * 16)
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_INT_CONFIG1			0x0064
2888c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_CONFIG1_TPULSE_DURATION	BIT(6)
2898c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_CONFIG1_TDEASSERT_DISABLE	BIT(5)
2908c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_CONFIG1_ASYNC_RESET		BIT(4)
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_INT_SOURCE0			0x0065
2938c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_SOURCE0_UI_FSYNC_INT1_EN	BIT(6)
2948c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_SOURCE0_PLL_RDY_INT1_EN	BIT(5)
2958c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_SOURCE0_RESET_DONE_INT1_EN	BIT(4)
2968c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_SOURCE0_UI_DRDY_INT1_EN	BIT(3)
2978c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN	BIT(2)
2988c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_SOURCE0_FIFO_FULL_INT1_EN	BIT(1)
2998c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_SOURCE0_UI_AGC_RDY_INT1_EN	BIT(0)
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_WHOAMI				0x0075
3028c2ecf20Sopenharmony_ci#define INV_ICM42600_WHOAMI_ICM42600			0x40
3038c2ecf20Sopenharmony_ci#define INV_ICM42600_WHOAMI_ICM42602			0x41
3048c2ecf20Sopenharmony_ci#define INV_ICM42600_WHOAMI_ICM42605			0x42
3058c2ecf20Sopenharmony_ci#define INV_ICM42600_WHOAMI_ICM42622			0x46
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci/* User bank 1 (MSB 0x10) */
3088c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_SENSOR_CONFIG0			0x1003
3098c2ecf20Sopenharmony_ci#define INV_ICM42600_SENSOR_CONFIG0_ZG_DISABLE		BIT(5)
3108c2ecf20Sopenharmony_ci#define INV_ICM42600_SENSOR_CONFIG0_YG_DISABLE		BIT(4)
3118c2ecf20Sopenharmony_ci#define INV_ICM42600_SENSOR_CONFIG0_XG_DISABLE		BIT(3)
3128c2ecf20Sopenharmony_ci#define INV_ICM42600_SENSOR_CONFIG0_ZA_DISABLE		BIT(2)
3138c2ecf20Sopenharmony_ci#define INV_ICM42600_SENSOR_CONFIG0_YA_DISABLE		BIT(1)
3148c2ecf20Sopenharmony_ci#define INV_ICM42600_SENSOR_CONFIG0_XA_DISABLE		BIT(0)
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci/* Timestamp value is 20 bits (3 registers) in little-endian */
3178c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_TMSTVAL			0x1062
3188c2ecf20Sopenharmony_ci#define INV_ICM42600_TMSTVAL_MASK			GENMASK(19, 0)
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_INTF_CONFIG4			0x107A
3218c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG4_I3C_BUS_ONLY		BIT(6)
3228c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG4_SPI_AP_4WIRE		BIT(1)
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_INTF_CONFIG6			0x107C
3258c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG6_MASK			GENMASK(4, 0)
3268c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG6_I3C_EN		BIT(4)
3278c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG6_I3C_IBI_BYTE_EN	BIT(3)
3288c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG6_I3C_IBI_EN		BIT(2)
3298c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG6_I3C_DDR_EN		BIT(1)
3308c2ecf20Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG6_I3C_SDR_EN		BIT(0)
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci/* User bank 4 (MSB 0x40) */
3338c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_INT_SOURCE8			0x404F
3348c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_SOURCE8_FSYNC_IBI_EN		BIT(5)
3358c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_SOURCE8_PLL_RDY_IBI_EN		BIT(4)
3368c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_SOURCE8_UI_DRDY_IBI_EN		BIT(3)
3378c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_SOURCE8_FIFO_THS_IBI_EN	BIT(2)
3388c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_SOURCE8_FIFO_FULL_IBI_EN	BIT(1)
3398c2ecf20Sopenharmony_ci#define INV_ICM42600_INT_SOURCE8_AGC_RDY_IBI_EN		BIT(0)
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER0			0x4077
3428c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER1			0x4078
3438c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER2			0x4079
3448c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER3			0x407A
3458c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER4			0x407B
3468c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER5			0x407C
3478c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER6			0x407D
3488c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER7			0x407E
3498c2ecf20Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER8			0x407F
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci/* Sleep times required by the driver */
3528c2ecf20Sopenharmony_ci#define INV_ICM42600_POWER_UP_TIME_MS		100
3538c2ecf20Sopenharmony_ci#define INV_ICM42600_RESET_TIME_MS		1
3548c2ecf20Sopenharmony_ci#define INV_ICM42600_ACCEL_STARTUP_TIME_MS	20
3558c2ecf20Sopenharmony_ci#define INV_ICM42600_GYRO_STARTUP_TIME_MS	60
3568c2ecf20Sopenharmony_ci#define INV_ICM42600_GYRO_STOP_TIME_MS		150
3578c2ecf20Sopenharmony_ci#define INV_ICM42600_TEMP_STARTUP_TIME_MS	14
3588c2ecf20Sopenharmony_ci#define INV_ICM42600_SUSPEND_DELAY_MS		2000
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_citypedef int (*inv_icm42600_bus_setup)(struct inv_icm42600_state *);
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ciextern const struct regmap_config inv_icm42600_regmap_config;
3638c2ecf20Sopenharmony_ciextern const struct dev_pm_ops inv_icm42600_pm_ops;
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ciconst struct iio_mount_matrix *
3668c2ecf20Sopenharmony_ciinv_icm42600_get_mount_matrix(const struct iio_dev *indio_dev,
3678c2ecf20Sopenharmony_ci			      const struct iio_chan_spec *chan);
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ciuint32_t inv_icm42600_odr_to_period(enum inv_icm42600_odr odr);
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ciint inv_icm42600_set_accel_conf(struct inv_icm42600_state *st,
3728c2ecf20Sopenharmony_ci				struct inv_icm42600_sensor_conf *conf,
3738c2ecf20Sopenharmony_ci				unsigned int *sleep_ms);
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ciint inv_icm42600_set_gyro_conf(struct inv_icm42600_state *st,
3768c2ecf20Sopenharmony_ci			       struct inv_icm42600_sensor_conf *conf,
3778c2ecf20Sopenharmony_ci			       unsigned int *sleep_ms);
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ciint inv_icm42600_set_temp_conf(struct inv_icm42600_state *st, bool enable,
3808c2ecf20Sopenharmony_ci			       unsigned int *sleep_ms);
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ciint inv_icm42600_debugfs_reg(struct iio_dev *indio_dev, unsigned int reg,
3838c2ecf20Sopenharmony_ci			     unsigned int writeval, unsigned int *readval);
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ciint inv_icm42600_core_probe(struct regmap *regmap, int chip, int irq,
3868c2ecf20Sopenharmony_ci			    inv_icm42600_bus_setup bus_setup);
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_cistruct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st);
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ciint inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev);
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_cistruct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st);
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ciint inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev);
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci#endif
397