xref: /openbmc/linux/drivers/iio/imu/inv_icm42600/inv_icm42600.h (revision aad29a73199b7fbccfbabea3f1ee627ad1924f52)
131c24c1eSJean-Baptiste Maneyrol /* SPDX-License-Identifier: GPL-2.0-or-later */
231c24c1eSJean-Baptiste Maneyrol /*
331c24c1eSJean-Baptiste Maneyrol  * Copyright (C) 2020 Invensense, Inc.
431c24c1eSJean-Baptiste Maneyrol  */
531c24c1eSJean-Baptiste Maneyrol 
631c24c1eSJean-Baptiste Maneyrol #ifndef INV_ICM42600_H_
731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_H_
831c24c1eSJean-Baptiste Maneyrol 
931c24c1eSJean-Baptiste Maneyrol #include <linux/bits.h>
1031c24c1eSJean-Baptiste Maneyrol #include <linux/bitfield.h>
1131c24c1eSJean-Baptiste Maneyrol #include <linux/regmap.h>
1231c24c1eSJean-Baptiste Maneyrol #include <linux/mutex.h>
1331c24c1eSJean-Baptiste Maneyrol #include <linux/regulator/consumer.h>
1431c24c1eSJean-Baptiste Maneyrol #include <linux/pm.h>
1531c24c1eSJean-Baptiste Maneyrol #include <linux/iio/iio.h>
1631c24c1eSJean-Baptiste Maneyrol 
177f85e42aSJean-Baptiste Maneyrol #include "inv_icm42600_buffer.h"
187f85e42aSJean-Baptiste Maneyrol 
1931c24c1eSJean-Baptiste Maneyrol enum inv_icm42600_chip {
20106b391eSJean-Baptiste Maneyrol 	INV_CHIP_INVALID,
2131c24c1eSJean-Baptiste Maneyrol 	INV_CHIP_ICM42600,
2231c24c1eSJean-Baptiste Maneyrol 	INV_CHIP_ICM42602,
2331c24c1eSJean-Baptiste Maneyrol 	INV_CHIP_ICM42605,
2431c24c1eSJean-Baptiste Maneyrol 	INV_CHIP_ICM42622,
25c896b9f0SJay Greco 	INV_CHIP_ICM42631,
2631c24c1eSJean-Baptiste Maneyrol 	INV_CHIP_NB,
2731c24c1eSJean-Baptiste Maneyrol };
2831c24c1eSJean-Baptiste Maneyrol 
2931c24c1eSJean-Baptiste Maneyrol /* serial bus slew rates */
3031c24c1eSJean-Baptiste Maneyrol enum inv_icm42600_slew_rate {
3131c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_SLEW_RATE_20_60NS,
3231c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_SLEW_RATE_12_36NS,
3331c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_SLEW_RATE_6_18NS,
3431c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_SLEW_RATE_4_12NS,
3531c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_SLEW_RATE_2_6NS,
3631c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_SLEW_RATE_INF_2NS,
3731c24c1eSJean-Baptiste Maneyrol };
3831c24c1eSJean-Baptiste Maneyrol 
3931c24c1eSJean-Baptiste Maneyrol enum inv_icm42600_sensor_mode {
4031c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_SENSOR_MODE_OFF,
4131c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_SENSOR_MODE_STANDBY,
4231c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_SENSOR_MODE_LOW_POWER,
4331c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_SENSOR_MODE_LOW_NOISE,
4431c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_SENSOR_MODE_NB,
4531c24c1eSJean-Baptiste Maneyrol };
4631c24c1eSJean-Baptiste Maneyrol 
4731c24c1eSJean-Baptiste Maneyrol /* gyroscope fullscale values */
4831c24c1eSJean-Baptiste Maneyrol enum inv_icm42600_gyro_fs {
4931c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_GYRO_FS_2000DPS,
5031c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_GYRO_FS_1000DPS,
5131c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_GYRO_FS_500DPS,
5231c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_GYRO_FS_250DPS,
5331c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_GYRO_FS_125DPS,
5431c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_GYRO_FS_62_5DPS,
5531c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_GYRO_FS_31_25DPS,
5631c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_GYRO_FS_15_625DPS,
5731c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_GYRO_FS_NB,
5831c24c1eSJean-Baptiste Maneyrol };
5931c24c1eSJean-Baptiste Maneyrol 
6031c24c1eSJean-Baptiste Maneyrol /* accelerometer fullscale values */
6131c24c1eSJean-Baptiste Maneyrol enum inv_icm42600_accel_fs {
6231c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ACCEL_FS_16G,
6331c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ACCEL_FS_8G,
6431c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ACCEL_FS_4G,
6531c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ACCEL_FS_2G,
6631c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ACCEL_FS_NB,
6731c24c1eSJean-Baptiste Maneyrol };
6831c24c1eSJean-Baptiste Maneyrol 
6931c24c1eSJean-Baptiste Maneyrol /* ODR suffixed by LN or LP are Low-Noise or Low-Power mode only */
7031c24c1eSJean-Baptiste Maneyrol enum inv_icm42600_odr {
7131c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ODR_8KHZ_LN = 3,
7231c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ODR_4KHZ_LN,
7331c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ODR_2KHZ_LN,
7431c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ODR_1KHZ_LN,
7531c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ODR_200HZ,
7631c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ODR_100HZ,
7731c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ODR_50HZ,
7831c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ODR_25HZ,
7931c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ODR_12_5HZ,
8031c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ODR_6_25HZ_LP,
8131c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ODR_3_125HZ_LP,
8231c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ODR_1_5625HZ_LP,
8331c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ODR_500HZ,
8431c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_ODR_NB,
8531c24c1eSJean-Baptiste Maneyrol };
8631c24c1eSJean-Baptiste Maneyrol 
8731c24c1eSJean-Baptiste Maneyrol enum inv_icm42600_filter {
8831c24c1eSJean-Baptiste Maneyrol 	/* Low-Noise mode sensor data filter (3rd order filter by default) */
8931c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_FILTER_BW_ODR_DIV_2,
9031c24c1eSJean-Baptiste Maneyrol 
9131c24c1eSJean-Baptiste Maneyrol 	/* Low-Power mode sensor data filter (averaging) */
9231c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_FILTER_AVG_1X = 1,
9331c24c1eSJean-Baptiste Maneyrol 	INV_ICM42600_FILTER_AVG_16X = 6,
9431c24c1eSJean-Baptiste Maneyrol };
9531c24c1eSJean-Baptiste Maneyrol 
9631c24c1eSJean-Baptiste Maneyrol struct inv_icm42600_sensor_conf {
9731c24c1eSJean-Baptiste Maneyrol 	int mode;
9831c24c1eSJean-Baptiste Maneyrol 	int fs;
9931c24c1eSJean-Baptiste Maneyrol 	int odr;
10031c24c1eSJean-Baptiste Maneyrol 	int filter;
10131c24c1eSJean-Baptiste Maneyrol };
10231c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_SENSOR_CONF_INIT		{-1, -1, -1, -1}
10331c24c1eSJean-Baptiste Maneyrol 
10431c24c1eSJean-Baptiste Maneyrol struct inv_icm42600_conf {
10531c24c1eSJean-Baptiste Maneyrol 	struct inv_icm42600_sensor_conf gyro;
10631c24c1eSJean-Baptiste Maneyrol 	struct inv_icm42600_sensor_conf accel;
10731c24c1eSJean-Baptiste Maneyrol 	bool temp_en;
10831c24c1eSJean-Baptiste Maneyrol };
10931c24c1eSJean-Baptiste Maneyrol 
11031c24c1eSJean-Baptiste Maneyrol struct inv_icm42600_suspended {
11131c24c1eSJean-Baptiste Maneyrol 	enum inv_icm42600_sensor_mode gyro;
11231c24c1eSJean-Baptiste Maneyrol 	enum inv_icm42600_sensor_mode accel;
11331c24c1eSJean-Baptiste Maneyrol 	bool temp;
11431c24c1eSJean-Baptiste Maneyrol };
11531c24c1eSJean-Baptiste Maneyrol 
11631c24c1eSJean-Baptiste Maneyrol /**
11731c24c1eSJean-Baptiste Maneyrol  *  struct inv_icm42600_state - driver state variables
11831c24c1eSJean-Baptiste Maneyrol  *  @lock:		lock for serializing multiple registers access.
11931c24c1eSJean-Baptiste Maneyrol  *  @chip:		chip identifier.
12031c24c1eSJean-Baptiste Maneyrol  *  @name:		chip name.
12131c24c1eSJean-Baptiste Maneyrol  *  @map:		regmap pointer.
12231c24c1eSJean-Baptiste Maneyrol  *  @vdd_supply:	VDD voltage regulator for the chip.
12331c24c1eSJean-Baptiste Maneyrol  *  @vddio_supply:	I/O voltage regulator for the chip.
12431c24c1eSJean-Baptiste Maneyrol  *  @orientation:	sensor chip orientation relative to main hardware.
12531c24c1eSJean-Baptiste Maneyrol  *  @conf:		chip sensors configurations.
12631c24c1eSJean-Baptiste Maneyrol  *  @suspended:		suspended sensors configuration.
127a095fadbSJean-Baptiste Maneyrol  *  @indio_gyro:	gyroscope IIO device.
128a47c1cdcSJean-Baptiste Maneyrol  *  @indio_accel:	accelerometer IIO device.
129a095fadbSJean-Baptiste Maneyrol  *  @buffer:		data transfer buffer aligned for DMA.
1307f85e42aSJean-Baptiste Maneyrol  *  @fifo:		FIFO management structure.
131ec74ae9fSJean-Baptiste Maneyrol  *  @timestamp:		interrupt timestamps.
13231c24c1eSJean-Baptiste Maneyrol  */
13331c24c1eSJean-Baptiste Maneyrol struct inv_icm42600_state {
13431c24c1eSJean-Baptiste Maneyrol 	struct mutex lock;
13531c24c1eSJean-Baptiste Maneyrol 	enum inv_icm42600_chip chip;
13631c24c1eSJean-Baptiste Maneyrol 	const char *name;
13731c24c1eSJean-Baptiste Maneyrol 	struct regmap *map;
13831c24c1eSJean-Baptiste Maneyrol 	struct regulator *vdd_supply;
13931c24c1eSJean-Baptiste Maneyrol 	struct regulator *vddio_supply;
14031c24c1eSJean-Baptiste Maneyrol 	struct iio_mount_matrix orientation;
14131c24c1eSJean-Baptiste Maneyrol 	struct inv_icm42600_conf conf;
14231c24c1eSJean-Baptiste Maneyrol 	struct inv_icm42600_suspended suspended;
143a095fadbSJean-Baptiste Maneyrol 	struct iio_dev *indio_gyro;
144a47c1cdcSJean-Baptiste Maneyrol 	struct iio_dev *indio_accel;
14584884770SJonathan Cameron 	uint8_t buffer[2] __aligned(IIO_DMA_MINALIGN);
1467f85e42aSJean-Baptiste Maneyrol 	struct inv_icm42600_fifo fifo;
147ec74ae9fSJean-Baptiste Maneyrol 	struct {
148ec74ae9fSJean-Baptiste Maneyrol 		int64_t gyro;
149ec74ae9fSJean-Baptiste Maneyrol 		int64_t accel;
150ec74ae9fSJean-Baptiste Maneyrol 	} timestamp;
15131c24c1eSJean-Baptiste Maneyrol };
15231c24c1eSJean-Baptiste Maneyrol 
15331c24c1eSJean-Baptiste Maneyrol /* Virtual register addresses: @bank on MSB (4 upper bits), @address on LSB */
15431c24c1eSJean-Baptiste Maneyrol 
15531c24c1eSJean-Baptiste Maneyrol /* Bank selection register, available in all banks */
15631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_BANK_SEL			0x76
15731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_BANK_SEL_MASK			GENMASK(2, 0)
15831c24c1eSJean-Baptiste Maneyrol 
15931c24c1eSJean-Baptiste Maneyrol /* User bank 0 (MSB 0x00) */
16031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_DEVICE_CONFIG			0x0011
16131c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_DEVICE_CONFIG_SOFT_RESET		BIT(0)
16231c24c1eSJean-Baptiste Maneyrol 
16331c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_DRIVE_CONFIG			0x0013
16431c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_DRIVE_CONFIG_I2C_MASK		GENMASK(5, 3)
16531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_DRIVE_CONFIG_I2C(_rate)		\
16631c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(INV_ICM42600_DRIVE_CONFIG_I2C_MASK, (_rate))
16731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_DRIVE_CONFIG_SPI_MASK		GENMASK(2, 0)
16831c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_DRIVE_CONFIG_SPI(_rate)		\
16931c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(INV_ICM42600_DRIVE_CONFIG_SPI_MASK, (_rate))
17031c24c1eSJean-Baptiste Maneyrol 
17131c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_INT_CONFIG			0x0014
17231c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_CONFIG_INT2_LATCHED		BIT(5)
17331c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_CONFIG_INT2_PUSH_PULL		BIT(4)
17431c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_CONFIG_INT2_ACTIVE_HIGH	BIT(3)
17531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_CONFIG_INT2_ACTIVE_LOW		0x00
17631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_CONFIG_INT1_LATCHED		BIT(2)
17731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_CONFIG_INT1_PUSH_PULL		BIT(1)
17831c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_CONFIG_INT1_ACTIVE_HIGH	BIT(0)
17931c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_CONFIG_INT1_ACTIVE_LOW		0x00
18031c24c1eSJean-Baptiste Maneyrol 
18131c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_FIFO_CONFIG			0x0016
18231c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_FIFO_CONFIG_MASK			GENMASK(7, 6)
18331c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_FIFO_CONFIG_BYPASS			\
18431c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 0)
18531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_FIFO_CONFIG_STREAM			\
18631c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 1)
18731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_FIFO_CONFIG_STOP_ON_FULL		\
18831c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 2)
18931c24c1eSJean-Baptiste Maneyrol 
19031c24c1eSJean-Baptiste Maneyrol /* all sensor data are 16 bits (2 registers wide) in big-endian */
19131c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_TEMP_DATA			0x001D
19231c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_ACCEL_DATA_X			0x001F
19331c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_ACCEL_DATA_Y			0x0021
19431c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_ACCEL_DATA_Z			0x0023
19531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_GYRO_DATA_X			0x0025
19631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_GYRO_DATA_Y			0x0027
19731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_GYRO_DATA_Z			0x0029
19831c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_DATA_INVALID			-32768
19931c24c1eSJean-Baptiste Maneyrol 
20031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_INT_STATUS			0x002D
20131c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_STATUS_UI_FSYNC		BIT(6)
20231c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_STATUS_PLL_RDY			BIT(5)
20331c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_STATUS_RESET_DONE		BIT(4)
20431c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_STATUS_DATA_RDY		BIT(3)
20531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_STATUS_FIFO_THS		BIT(2)
20631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_STATUS_FIFO_FULL		BIT(1)
20731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_STATUS_AGC_RDY			BIT(0)
20831c24c1eSJean-Baptiste Maneyrol 
20931c24c1eSJean-Baptiste Maneyrol /*
21031c24c1eSJean-Baptiste Maneyrol  * FIFO access registers
21131c24c1eSJean-Baptiste Maneyrol  * FIFO count is 16 bits (2 registers) big-endian
21231c24c1eSJean-Baptiste Maneyrol  * FIFO data is a continuous read register to read FIFO content
21331c24c1eSJean-Baptiste Maneyrol  */
21431c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_FIFO_COUNT			0x002E
21531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_FIFO_DATA			0x0030
21631c24c1eSJean-Baptiste Maneyrol 
21731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_SIGNAL_PATH_RESET		0x004B
21831c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_SIGNAL_PATH_RESET_DMP_INIT_EN	BIT(6)
21931c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_SIGNAL_PATH_RESET_DMP_MEM_RESET	BIT(5)
22031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_SIGNAL_PATH_RESET_RESET		BIT(3)
22131c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_SIGNAL_PATH_RESET_TMST_STROBE	BIT(2)
22231c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH	BIT(1)
22331c24c1eSJean-Baptiste Maneyrol 
22431c24c1eSJean-Baptiste Maneyrol /* default configuration: all data big-endian and fifo count in bytes */
22531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_INTF_CONFIG0			0x004C
22631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG0_FIFO_HOLD_LAST_DATA	BIT(7)
22731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG0_FIFO_COUNT_REC	BIT(6)
22831c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG0_FIFO_COUNT_ENDIAN	BIT(5)
22931c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG0_SENSOR_DATA_ENDIAN	BIT(4)
23031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK	GENMASK(1, 0)
23131c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_SPI_DIS	\
23231c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK, 2)
23331c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_I2C_DIS	\
23431c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK, 3)
23531c24c1eSJean-Baptiste Maneyrol 
23631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_INTF_CONFIG1			0x004D
23731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG1_ACCEL_LP_CLK_RC	BIT(3)
23831c24c1eSJean-Baptiste Maneyrol 
23931c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_PWR_MGMT0			0x004E
24031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_PWR_MGMT0_TEMP_DIS			BIT(5)
24131c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_PWR_MGMT0_IDLE			BIT(4)
24231c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_PWR_MGMT0_GYRO(_mode)		\
24331c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(GENMASK(3, 2), (_mode))
24431c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_PWR_MGMT0_ACCEL(_mode)		\
24531c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(GENMASK(1, 0), (_mode))
24631c24c1eSJean-Baptiste Maneyrol 
24731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_GYRO_CONFIG0			0x004F
24831c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_GYRO_CONFIG0_FS(_fs)		\
24931c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(GENMASK(7, 5), (_fs))
25031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_GYRO_CONFIG0_ODR(_odr)		\
25131c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(GENMASK(3, 0), (_odr))
25231c24c1eSJean-Baptiste Maneyrol 
25331c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_ACCEL_CONFIG0			0x0050
25431c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_ACCEL_CONFIG0_FS(_fs)		\
25531c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(GENMASK(7, 5), (_fs))
25631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_ACCEL_CONFIG0_ODR(_odr)		\
25731c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(GENMASK(3, 0), (_odr))
25831c24c1eSJean-Baptiste Maneyrol 
25931c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_GYRO_ACCEL_CONFIG0		0x0052
26031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_GYRO_ACCEL_CONFIG0_ACCEL_FILT(_f)	\
26131c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(GENMASK(7, 4), (_f))
26231c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_GYRO_ACCEL_CONFIG0_GYRO_FILT(_f)	\
26331c24c1eSJean-Baptiste Maneyrol 		FIELD_PREP(GENMASK(3, 0), (_f))
26431c24c1eSJean-Baptiste Maneyrol 
26531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_TMST_CONFIG			0x0054
26631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_TMST_CONFIG_MASK			GENMASK(4, 0)
26731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_TMST_CONFIG_TMST_TO_REGS_EN	BIT(4)
26831c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_TMST_CONFIG_TMST_RES_16US		BIT(3)
26931c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_TMST_CONFIG_TMST_DELTA_EN		BIT(2)
27031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_TMST_CONFIG_TMST_FSYNC_EN		BIT(1)
27131c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_TMST_CONFIG_TMST_EN		BIT(0)
27231c24c1eSJean-Baptiste Maneyrol 
27331c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_FIFO_CONFIG1			0x005F
27431c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_FIFO_CONFIG1_RESUME_PARTIAL_RD	BIT(6)
27531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_FIFO_CONFIG1_WM_GT_TH		BIT(5)
27631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_FIFO_CONFIG1_TMST_FSYNC_EN		BIT(3)
27731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_FIFO_CONFIG1_TEMP_EN		BIT(2)
27831c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_FIFO_CONFIG1_GYRO_EN		BIT(1)
27931c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_FIFO_CONFIG1_ACCEL_EN		BIT(0)
28031c24c1eSJean-Baptiste Maneyrol 
28131c24c1eSJean-Baptiste Maneyrol /* FIFO watermark is 16 bits (2 registers wide) in little-endian */
28231c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_FIFO_WATERMARK			0x0060
28331c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_FIFO_WATERMARK_VAL(_wm)		\
28431c24c1eSJean-Baptiste Maneyrol 		cpu_to_le16((_wm) & GENMASK(11, 0))
28531c24c1eSJean-Baptiste Maneyrol /* FIFO is 2048 bytes, let 12 samples for reading latency */
28631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_FIFO_WATERMARK_MAX			(2048 - 12 * 16)
28731c24c1eSJean-Baptiste Maneyrol 
28831c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_INT_CONFIG1			0x0064
28931c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_CONFIG1_TPULSE_DURATION	BIT(6)
29031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_CONFIG1_TDEASSERT_DISABLE	BIT(5)
29131c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_CONFIG1_ASYNC_RESET		BIT(4)
29231c24c1eSJean-Baptiste Maneyrol 
29331c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_INT_SOURCE0			0x0065
29431c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_SOURCE0_UI_FSYNC_INT1_EN	BIT(6)
29531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_SOURCE0_PLL_RDY_INT1_EN	BIT(5)
29631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_SOURCE0_RESET_DONE_INT1_EN	BIT(4)
29731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_SOURCE0_UI_DRDY_INT1_EN	BIT(3)
29831c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN	BIT(2)
29931c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_SOURCE0_FIFO_FULL_INT1_EN	BIT(1)
30031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_SOURCE0_UI_AGC_RDY_INT1_EN	BIT(0)
30131c24c1eSJean-Baptiste Maneyrol 
30231c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_WHOAMI				0x0075
30331c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_WHOAMI_ICM42600			0x40
30431c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_WHOAMI_ICM42602			0x41
30531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_WHOAMI_ICM42605			0x42
30631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_WHOAMI_ICM42622			0x46
307c896b9f0SJay Greco #define INV_ICM42600_WHOAMI_ICM42631			0x5C
30831c24c1eSJean-Baptiste Maneyrol 
30931c24c1eSJean-Baptiste Maneyrol /* User bank 1 (MSB 0x10) */
31031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_SENSOR_CONFIG0			0x1003
31131c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_SENSOR_CONFIG0_ZG_DISABLE		BIT(5)
31231c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_SENSOR_CONFIG0_YG_DISABLE		BIT(4)
31331c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_SENSOR_CONFIG0_XG_DISABLE		BIT(3)
31431c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_SENSOR_CONFIG0_ZA_DISABLE		BIT(2)
31531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_SENSOR_CONFIG0_YA_DISABLE		BIT(1)
31631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_SENSOR_CONFIG0_XA_DISABLE		BIT(0)
31731c24c1eSJean-Baptiste Maneyrol 
31831c24c1eSJean-Baptiste Maneyrol /* Timestamp value is 20 bits (3 registers) in little-endian */
31931c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_TMSTVAL			0x1062
32031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_TMSTVAL_MASK			GENMASK(19, 0)
32131c24c1eSJean-Baptiste Maneyrol 
32231c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_INTF_CONFIG4			0x107A
32331c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG4_I3C_BUS_ONLY		BIT(6)
32431c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG4_SPI_AP_4WIRE		BIT(1)
32531c24c1eSJean-Baptiste Maneyrol 
32631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_INTF_CONFIG6			0x107C
32731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG6_MASK			GENMASK(4, 0)
32831c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG6_I3C_EN		BIT(4)
32931c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG6_I3C_IBI_BYTE_EN	BIT(3)
33031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG6_I3C_IBI_EN		BIT(2)
33131c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG6_I3C_DDR_EN		BIT(1)
33231c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INTF_CONFIG6_I3C_SDR_EN		BIT(0)
33331c24c1eSJean-Baptiste Maneyrol 
33431c24c1eSJean-Baptiste Maneyrol /* User bank 4 (MSB 0x40) */
33531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_INT_SOURCE8			0x404F
33631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_SOURCE8_FSYNC_IBI_EN		BIT(5)
33731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_SOURCE8_PLL_RDY_IBI_EN		BIT(4)
33831c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_SOURCE8_UI_DRDY_IBI_EN		BIT(3)
33931c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_SOURCE8_FIFO_THS_IBI_EN	BIT(2)
34031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_SOURCE8_FIFO_FULL_IBI_EN	BIT(1)
34131c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_INT_SOURCE8_AGC_RDY_IBI_EN		BIT(0)
34231c24c1eSJean-Baptiste Maneyrol 
34331c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_OFFSET_USER0			0x4077
34431c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_OFFSET_USER1			0x4078
34531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_OFFSET_USER2			0x4079
34631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_OFFSET_USER3			0x407A
34731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_OFFSET_USER4			0x407B
34831c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_OFFSET_USER5			0x407C
34931c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_OFFSET_USER6			0x407D
35031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_OFFSET_USER7			0x407E
35131c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_REG_OFFSET_USER8			0x407F
35231c24c1eSJean-Baptiste Maneyrol 
35331c24c1eSJean-Baptiste Maneyrol /* Sleep times required by the driver */
35431c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_POWER_UP_TIME_MS		100
35531c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_RESET_TIME_MS		1
35631c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_ACCEL_STARTUP_TIME_MS	20
35731c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_GYRO_STARTUP_TIME_MS	60
35831c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_GYRO_STOP_TIME_MS		150
35931c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_TEMP_STARTUP_TIME_MS	14
36031c24c1eSJean-Baptiste Maneyrol #define INV_ICM42600_SUSPEND_DELAY_MS		2000
36131c24c1eSJean-Baptiste Maneyrol 
36231c24c1eSJean-Baptiste Maneyrol typedef int (*inv_icm42600_bus_setup)(struct inv_icm42600_state *);
36331c24c1eSJean-Baptiste Maneyrol 
36431c24c1eSJean-Baptiste Maneyrol extern const struct regmap_config inv_icm42600_regmap_config;
365*c39d275eSJean-Baptiste Maneyrol extern const struct regmap_config inv_icm42600_spi_regmap_config;
36631c24c1eSJean-Baptiste Maneyrol extern const struct dev_pm_ops inv_icm42600_pm_ops;
36731c24c1eSJean-Baptiste Maneyrol 
36831c24c1eSJean-Baptiste Maneyrol const struct iio_mount_matrix *
36931c24c1eSJean-Baptiste Maneyrol inv_icm42600_get_mount_matrix(const struct iio_dev *indio_dev,
37031c24c1eSJean-Baptiste Maneyrol 			      const struct iio_chan_spec *chan);
37131c24c1eSJean-Baptiste Maneyrol 
37231c24c1eSJean-Baptiste Maneyrol uint32_t inv_icm42600_odr_to_period(enum inv_icm42600_odr odr);
37331c24c1eSJean-Baptiste Maneyrol 
37431c24c1eSJean-Baptiste Maneyrol int inv_icm42600_set_accel_conf(struct inv_icm42600_state *st,
37531c24c1eSJean-Baptiste Maneyrol 				struct inv_icm42600_sensor_conf *conf,
37631c24c1eSJean-Baptiste Maneyrol 				unsigned int *sleep_ms);
37731c24c1eSJean-Baptiste Maneyrol 
37831c24c1eSJean-Baptiste Maneyrol int inv_icm42600_set_gyro_conf(struct inv_icm42600_state *st,
37931c24c1eSJean-Baptiste Maneyrol 			       struct inv_icm42600_sensor_conf *conf,
38031c24c1eSJean-Baptiste Maneyrol 			       unsigned int *sleep_ms);
38131c24c1eSJean-Baptiste Maneyrol 
38231c24c1eSJean-Baptiste Maneyrol int inv_icm42600_set_temp_conf(struct inv_icm42600_state *st, bool enable,
38331c24c1eSJean-Baptiste Maneyrol 			       unsigned int *sleep_ms);
38431c24c1eSJean-Baptiste Maneyrol 
38531c24c1eSJean-Baptiste Maneyrol int inv_icm42600_debugfs_reg(struct iio_dev *indio_dev, unsigned int reg,
38631c24c1eSJean-Baptiste Maneyrol 			     unsigned int writeval, unsigned int *readval);
38731c24c1eSJean-Baptiste Maneyrol 
388e5efa104SJean-Baptiste Maneyrol int inv_icm42600_core_probe(struct regmap *regmap, int chip, int irq,
38931c24c1eSJean-Baptiste Maneyrol 			    inv_icm42600_bus_setup bus_setup);
39031c24c1eSJean-Baptiste Maneyrol 
391a095fadbSJean-Baptiste Maneyrol struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st);
392a095fadbSJean-Baptiste Maneyrol 
3937f85e42aSJean-Baptiste Maneyrol int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev);
3947f85e42aSJean-Baptiste Maneyrol 
395a47c1cdcSJean-Baptiste Maneyrol struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st);
396a47c1cdcSJean-Baptiste Maneyrol 
3977f85e42aSJean-Baptiste Maneyrol int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev);
3987f85e42aSJean-Baptiste Maneyrol 
39931c24c1eSJean-Baptiste Maneyrol #endif
400