162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2020 Invensense, Inc. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef INV_ICM42600_H_ 762306a36Sopenharmony_ci#define INV_ICM42600_H_ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include <linux/bits.h> 1062306a36Sopenharmony_ci#include <linux/bitfield.h> 1162306a36Sopenharmony_ci#include <linux/regmap.h> 1262306a36Sopenharmony_ci#include <linux/mutex.h> 1362306a36Sopenharmony_ci#include <linux/regulator/consumer.h> 1462306a36Sopenharmony_ci#include <linux/pm.h> 1562306a36Sopenharmony_ci#include <linux/iio/iio.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#include "inv_icm42600_buffer.h" 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_cienum inv_icm42600_chip { 2062306a36Sopenharmony_ci INV_CHIP_INVALID, 2162306a36Sopenharmony_ci INV_CHIP_ICM42600, 2262306a36Sopenharmony_ci INV_CHIP_ICM42602, 2362306a36Sopenharmony_ci INV_CHIP_ICM42605, 2462306a36Sopenharmony_ci INV_CHIP_ICM42622, 2562306a36Sopenharmony_ci INV_CHIP_ICM42631, 2662306a36Sopenharmony_ci INV_CHIP_NB, 2762306a36Sopenharmony_ci}; 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci/* serial bus slew rates */ 3062306a36Sopenharmony_cienum inv_icm42600_slew_rate { 3162306a36Sopenharmony_ci INV_ICM42600_SLEW_RATE_20_60NS, 3262306a36Sopenharmony_ci INV_ICM42600_SLEW_RATE_12_36NS, 3362306a36Sopenharmony_ci INV_ICM42600_SLEW_RATE_6_18NS, 3462306a36Sopenharmony_ci INV_ICM42600_SLEW_RATE_4_12NS, 3562306a36Sopenharmony_ci INV_ICM42600_SLEW_RATE_2_6NS, 3662306a36Sopenharmony_ci INV_ICM42600_SLEW_RATE_INF_2NS, 3762306a36Sopenharmony_ci}; 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_cienum inv_icm42600_sensor_mode { 4062306a36Sopenharmony_ci INV_ICM42600_SENSOR_MODE_OFF, 4162306a36Sopenharmony_ci INV_ICM42600_SENSOR_MODE_STANDBY, 4262306a36Sopenharmony_ci INV_ICM42600_SENSOR_MODE_LOW_POWER, 4362306a36Sopenharmony_ci INV_ICM42600_SENSOR_MODE_LOW_NOISE, 4462306a36Sopenharmony_ci INV_ICM42600_SENSOR_MODE_NB, 4562306a36Sopenharmony_ci}; 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci/* gyroscope fullscale values */ 4862306a36Sopenharmony_cienum inv_icm42600_gyro_fs { 4962306a36Sopenharmony_ci INV_ICM42600_GYRO_FS_2000DPS, 5062306a36Sopenharmony_ci INV_ICM42600_GYRO_FS_1000DPS, 5162306a36Sopenharmony_ci INV_ICM42600_GYRO_FS_500DPS, 5262306a36Sopenharmony_ci INV_ICM42600_GYRO_FS_250DPS, 5362306a36Sopenharmony_ci INV_ICM42600_GYRO_FS_125DPS, 5462306a36Sopenharmony_ci INV_ICM42600_GYRO_FS_62_5DPS, 5562306a36Sopenharmony_ci INV_ICM42600_GYRO_FS_31_25DPS, 5662306a36Sopenharmony_ci INV_ICM42600_GYRO_FS_15_625DPS, 5762306a36Sopenharmony_ci INV_ICM42600_GYRO_FS_NB, 5862306a36Sopenharmony_ci}; 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci/* accelerometer fullscale values */ 6162306a36Sopenharmony_cienum inv_icm42600_accel_fs { 6262306a36Sopenharmony_ci INV_ICM42600_ACCEL_FS_16G, 6362306a36Sopenharmony_ci INV_ICM42600_ACCEL_FS_8G, 6462306a36Sopenharmony_ci INV_ICM42600_ACCEL_FS_4G, 6562306a36Sopenharmony_ci INV_ICM42600_ACCEL_FS_2G, 6662306a36Sopenharmony_ci INV_ICM42600_ACCEL_FS_NB, 6762306a36Sopenharmony_ci}; 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci/* ODR suffixed by LN or LP are Low-Noise or Low-Power mode only */ 7062306a36Sopenharmony_cienum inv_icm42600_odr { 7162306a36Sopenharmony_ci INV_ICM42600_ODR_8KHZ_LN = 3, 7262306a36Sopenharmony_ci INV_ICM42600_ODR_4KHZ_LN, 7362306a36Sopenharmony_ci INV_ICM42600_ODR_2KHZ_LN, 7462306a36Sopenharmony_ci INV_ICM42600_ODR_1KHZ_LN, 7562306a36Sopenharmony_ci INV_ICM42600_ODR_200HZ, 7662306a36Sopenharmony_ci INV_ICM42600_ODR_100HZ, 7762306a36Sopenharmony_ci INV_ICM42600_ODR_50HZ, 7862306a36Sopenharmony_ci INV_ICM42600_ODR_25HZ, 7962306a36Sopenharmony_ci INV_ICM42600_ODR_12_5HZ, 8062306a36Sopenharmony_ci INV_ICM42600_ODR_6_25HZ_LP, 8162306a36Sopenharmony_ci INV_ICM42600_ODR_3_125HZ_LP, 8262306a36Sopenharmony_ci INV_ICM42600_ODR_1_5625HZ_LP, 8362306a36Sopenharmony_ci INV_ICM42600_ODR_500HZ, 8462306a36Sopenharmony_ci INV_ICM42600_ODR_NB, 8562306a36Sopenharmony_ci}; 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_cienum inv_icm42600_filter { 8862306a36Sopenharmony_ci /* Low-Noise mode sensor data filter (3rd order filter by default) */ 8962306a36Sopenharmony_ci INV_ICM42600_FILTER_BW_ODR_DIV_2, 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci /* Low-Power mode sensor data filter (averaging) */ 9262306a36Sopenharmony_ci INV_ICM42600_FILTER_AVG_1X = 1, 9362306a36Sopenharmony_ci INV_ICM42600_FILTER_AVG_16X = 6, 9462306a36Sopenharmony_ci}; 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_cistruct inv_icm42600_sensor_conf { 9762306a36Sopenharmony_ci int mode; 9862306a36Sopenharmony_ci int fs; 9962306a36Sopenharmony_ci int odr; 10062306a36Sopenharmony_ci int filter; 10162306a36Sopenharmony_ci}; 10262306a36Sopenharmony_ci#define INV_ICM42600_SENSOR_CONF_INIT {-1, -1, -1, -1} 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_cistruct inv_icm42600_conf { 10562306a36Sopenharmony_ci struct inv_icm42600_sensor_conf gyro; 10662306a36Sopenharmony_ci struct inv_icm42600_sensor_conf accel; 10762306a36Sopenharmony_ci bool temp_en; 10862306a36Sopenharmony_ci}; 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_cistruct inv_icm42600_suspended { 11162306a36Sopenharmony_ci enum inv_icm42600_sensor_mode gyro; 11262306a36Sopenharmony_ci enum inv_icm42600_sensor_mode accel; 11362306a36Sopenharmony_ci bool temp; 11462306a36Sopenharmony_ci}; 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci/** 11762306a36Sopenharmony_ci * struct inv_icm42600_state - driver state variables 11862306a36Sopenharmony_ci * @lock: lock for serializing multiple registers access. 11962306a36Sopenharmony_ci * @chip: chip identifier. 12062306a36Sopenharmony_ci * @name: chip name. 12162306a36Sopenharmony_ci * @map: regmap pointer. 12262306a36Sopenharmony_ci * @vdd_supply: VDD voltage regulator for the chip. 12362306a36Sopenharmony_ci * @vddio_supply: I/O voltage regulator for the chip. 12462306a36Sopenharmony_ci * @orientation: sensor chip orientation relative to main hardware. 12562306a36Sopenharmony_ci * @conf: chip sensors configurations. 12662306a36Sopenharmony_ci * @suspended: suspended sensors configuration. 12762306a36Sopenharmony_ci * @indio_gyro: gyroscope IIO device. 12862306a36Sopenharmony_ci * @indio_accel: accelerometer IIO device. 12962306a36Sopenharmony_ci * @buffer: data transfer buffer aligned for DMA. 13062306a36Sopenharmony_ci * @fifo: FIFO management structure. 13162306a36Sopenharmony_ci * @timestamp: interrupt timestamps. 13262306a36Sopenharmony_ci */ 13362306a36Sopenharmony_cistruct inv_icm42600_state { 13462306a36Sopenharmony_ci struct mutex lock; 13562306a36Sopenharmony_ci enum inv_icm42600_chip chip; 13662306a36Sopenharmony_ci const char *name; 13762306a36Sopenharmony_ci struct regmap *map; 13862306a36Sopenharmony_ci struct regulator *vdd_supply; 13962306a36Sopenharmony_ci struct regulator *vddio_supply; 14062306a36Sopenharmony_ci struct iio_mount_matrix orientation; 14162306a36Sopenharmony_ci struct inv_icm42600_conf conf; 14262306a36Sopenharmony_ci struct inv_icm42600_suspended suspended; 14362306a36Sopenharmony_ci struct iio_dev *indio_gyro; 14462306a36Sopenharmony_ci struct iio_dev *indio_accel; 14562306a36Sopenharmony_ci uint8_t buffer[2] __aligned(IIO_DMA_MINALIGN); 14662306a36Sopenharmony_ci struct inv_icm42600_fifo fifo; 14762306a36Sopenharmony_ci struct { 14862306a36Sopenharmony_ci int64_t gyro; 14962306a36Sopenharmony_ci int64_t accel; 15062306a36Sopenharmony_ci } timestamp; 15162306a36Sopenharmony_ci}; 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ci/* Virtual register addresses: @bank on MSB (4 upper bits), @address on LSB */ 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci/* Bank selection register, available in all banks */ 15662306a36Sopenharmony_ci#define INV_ICM42600_REG_BANK_SEL 0x76 15762306a36Sopenharmony_ci#define INV_ICM42600_BANK_SEL_MASK GENMASK(2, 0) 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci/* User bank 0 (MSB 0x00) */ 16062306a36Sopenharmony_ci#define INV_ICM42600_REG_DEVICE_CONFIG 0x0011 16162306a36Sopenharmony_ci#define INV_ICM42600_DEVICE_CONFIG_SOFT_RESET BIT(0) 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci#define INV_ICM42600_REG_DRIVE_CONFIG 0x0013 16462306a36Sopenharmony_ci#define INV_ICM42600_DRIVE_CONFIG_I2C_MASK GENMASK(5, 3) 16562306a36Sopenharmony_ci#define INV_ICM42600_DRIVE_CONFIG_I2C(_rate) \ 16662306a36Sopenharmony_ci FIELD_PREP(INV_ICM42600_DRIVE_CONFIG_I2C_MASK, (_rate)) 16762306a36Sopenharmony_ci#define INV_ICM42600_DRIVE_CONFIG_SPI_MASK GENMASK(2, 0) 16862306a36Sopenharmony_ci#define INV_ICM42600_DRIVE_CONFIG_SPI(_rate) \ 16962306a36Sopenharmony_ci FIELD_PREP(INV_ICM42600_DRIVE_CONFIG_SPI_MASK, (_rate)) 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci#define INV_ICM42600_REG_INT_CONFIG 0x0014 17262306a36Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT2_LATCHED BIT(5) 17362306a36Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT2_PUSH_PULL BIT(4) 17462306a36Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT2_ACTIVE_HIGH BIT(3) 17562306a36Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT2_ACTIVE_LOW 0x00 17662306a36Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT1_LATCHED BIT(2) 17762306a36Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT1_PUSH_PULL BIT(1) 17862306a36Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT1_ACTIVE_HIGH BIT(0) 17962306a36Sopenharmony_ci#define INV_ICM42600_INT_CONFIG_INT1_ACTIVE_LOW 0x00 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci#define INV_ICM42600_REG_FIFO_CONFIG 0x0016 18262306a36Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG_MASK GENMASK(7, 6) 18362306a36Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG_BYPASS \ 18462306a36Sopenharmony_ci FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 0) 18562306a36Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG_STREAM \ 18662306a36Sopenharmony_ci FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 1) 18762306a36Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG_STOP_ON_FULL \ 18862306a36Sopenharmony_ci FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 2) 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ci/* all sensor data are 16 bits (2 registers wide) in big-endian */ 19162306a36Sopenharmony_ci#define INV_ICM42600_REG_TEMP_DATA 0x001D 19262306a36Sopenharmony_ci#define INV_ICM42600_REG_ACCEL_DATA_X 0x001F 19362306a36Sopenharmony_ci#define INV_ICM42600_REG_ACCEL_DATA_Y 0x0021 19462306a36Sopenharmony_ci#define INV_ICM42600_REG_ACCEL_DATA_Z 0x0023 19562306a36Sopenharmony_ci#define INV_ICM42600_REG_GYRO_DATA_X 0x0025 19662306a36Sopenharmony_ci#define INV_ICM42600_REG_GYRO_DATA_Y 0x0027 19762306a36Sopenharmony_ci#define INV_ICM42600_REG_GYRO_DATA_Z 0x0029 19862306a36Sopenharmony_ci#define INV_ICM42600_DATA_INVALID -32768 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci#define INV_ICM42600_REG_INT_STATUS 0x002D 20162306a36Sopenharmony_ci#define INV_ICM42600_INT_STATUS_UI_FSYNC BIT(6) 20262306a36Sopenharmony_ci#define INV_ICM42600_INT_STATUS_PLL_RDY BIT(5) 20362306a36Sopenharmony_ci#define INV_ICM42600_INT_STATUS_RESET_DONE BIT(4) 20462306a36Sopenharmony_ci#define INV_ICM42600_INT_STATUS_DATA_RDY BIT(3) 20562306a36Sopenharmony_ci#define INV_ICM42600_INT_STATUS_FIFO_THS BIT(2) 20662306a36Sopenharmony_ci#define INV_ICM42600_INT_STATUS_FIFO_FULL BIT(1) 20762306a36Sopenharmony_ci#define INV_ICM42600_INT_STATUS_AGC_RDY BIT(0) 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci/* 21062306a36Sopenharmony_ci * FIFO access registers 21162306a36Sopenharmony_ci * FIFO count is 16 bits (2 registers) big-endian 21262306a36Sopenharmony_ci * FIFO data is a continuous read register to read FIFO content 21362306a36Sopenharmony_ci */ 21462306a36Sopenharmony_ci#define INV_ICM42600_REG_FIFO_COUNT 0x002E 21562306a36Sopenharmony_ci#define INV_ICM42600_REG_FIFO_DATA 0x0030 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci#define INV_ICM42600_REG_SIGNAL_PATH_RESET 0x004B 21862306a36Sopenharmony_ci#define INV_ICM42600_SIGNAL_PATH_RESET_DMP_INIT_EN BIT(6) 21962306a36Sopenharmony_ci#define INV_ICM42600_SIGNAL_PATH_RESET_DMP_MEM_RESET BIT(5) 22062306a36Sopenharmony_ci#define INV_ICM42600_SIGNAL_PATH_RESET_RESET BIT(3) 22162306a36Sopenharmony_ci#define INV_ICM42600_SIGNAL_PATH_RESET_TMST_STROBE BIT(2) 22262306a36Sopenharmony_ci#define INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH BIT(1) 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ci/* default configuration: all data big-endian and fifo count in bytes */ 22562306a36Sopenharmony_ci#define INV_ICM42600_REG_INTF_CONFIG0 0x004C 22662306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG0_FIFO_HOLD_LAST_DATA BIT(7) 22762306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG0_FIFO_COUNT_REC BIT(6) 22862306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG0_FIFO_COUNT_ENDIAN BIT(5) 22962306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG0_SENSOR_DATA_ENDIAN BIT(4) 23062306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK GENMASK(1, 0) 23162306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_SPI_DIS \ 23262306a36Sopenharmony_ci FIELD_PREP(INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK, 2) 23362306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_I2C_DIS \ 23462306a36Sopenharmony_ci FIELD_PREP(INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK, 3) 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ci#define INV_ICM42600_REG_INTF_CONFIG1 0x004D 23762306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG1_ACCEL_LP_CLK_RC BIT(3) 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ci#define INV_ICM42600_REG_PWR_MGMT0 0x004E 24062306a36Sopenharmony_ci#define INV_ICM42600_PWR_MGMT0_TEMP_DIS BIT(5) 24162306a36Sopenharmony_ci#define INV_ICM42600_PWR_MGMT0_IDLE BIT(4) 24262306a36Sopenharmony_ci#define INV_ICM42600_PWR_MGMT0_GYRO(_mode) \ 24362306a36Sopenharmony_ci FIELD_PREP(GENMASK(3, 2), (_mode)) 24462306a36Sopenharmony_ci#define INV_ICM42600_PWR_MGMT0_ACCEL(_mode) \ 24562306a36Sopenharmony_ci FIELD_PREP(GENMASK(1, 0), (_mode)) 24662306a36Sopenharmony_ci 24762306a36Sopenharmony_ci#define INV_ICM42600_REG_GYRO_CONFIG0 0x004F 24862306a36Sopenharmony_ci#define INV_ICM42600_GYRO_CONFIG0_FS(_fs) \ 24962306a36Sopenharmony_ci FIELD_PREP(GENMASK(7, 5), (_fs)) 25062306a36Sopenharmony_ci#define INV_ICM42600_GYRO_CONFIG0_ODR(_odr) \ 25162306a36Sopenharmony_ci FIELD_PREP(GENMASK(3, 0), (_odr)) 25262306a36Sopenharmony_ci 25362306a36Sopenharmony_ci#define INV_ICM42600_REG_ACCEL_CONFIG0 0x0050 25462306a36Sopenharmony_ci#define INV_ICM42600_ACCEL_CONFIG0_FS(_fs) \ 25562306a36Sopenharmony_ci FIELD_PREP(GENMASK(7, 5), (_fs)) 25662306a36Sopenharmony_ci#define INV_ICM42600_ACCEL_CONFIG0_ODR(_odr) \ 25762306a36Sopenharmony_ci FIELD_PREP(GENMASK(3, 0), (_odr)) 25862306a36Sopenharmony_ci 25962306a36Sopenharmony_ci#define INV_ICM42600_REG_GYRO_ACCEL_CONFIG0 0x0052 26062306a36Sopenharmony_ci#define INV_ICM42600_GYRO_ACCEL_CONFIG0_ACCEL_FILT(_f) \ 26162306a36Sopenharmony_ci FIELD_PREP(GENMASK(7, 4), (_f)) 26262306a36Sopenharmony_ci#define INV_ICM42600_GYRO_ACCEL_CONFIG0_GYRO_FILT(_f) \ 26362306a36Sopenharmony_ci FIELD_PREP(GENMASK(3, 0), (_f)) 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_ci#define INV_ICM42600_REG_TMST_CONFIG 0x0054 26662306a36Sopenharmony_ci#define INV_ICM42600_TMST_CONFIG_MASK GENMASK(4, 0) 26762306a36Sopenharmony_ci#define INV_ICM42600_TMST_CONFIG_TMST_TO_REGS_EN BIT(4) 26862306a36Sopenharmony_ci#define INV_ICM42600_TMST_CONFIG_TMST_RES_16US BIT(3) 26962306a36Sopenharmony_ci#define INV_ICM42600_TMST_CONFIG_TMST_DELTA_EN BIT(2) 27062306a36Sopenharmony_ci#define INV_ICM42600_TMST_CONFIG_TMST_FSYNC_EN BIT(1) 27162306a36Sopenharmony_ci#define INV_ICM42600_TMST_CONFIG_TMST_EN BIT(0) 27262306a36Sopenharmony_ci 27362306a36Sopenharmony_ci#define INV_ICM42600_REG_FIFO_CONFIG1 0x005F 27462306a36Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG1_RESUME_PARTIAL_RD BIT(6) 27562306a36Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG1_WM_GT_TH BIT(5) 27662306a36Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG1_TMST_FSYNC_EN BIT(3) 27762306a36Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG1_TEMP_EN BIT(2) 27862306a36Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG1_GYRO_EN BIT(1) 27962306a36Sopenharmony_ci#define INV_ICM42600_FIFO_CONFIG1_ACCEL_EN BIT(0) 28062306a36Sopenharmony_ci 28162306a36Sopenharmony_ci/* FIFO watermark is 16 bits (2 registers wide) in little-endian */ 28262306a36Sopenharmony_ci#define INV_ICM42600_REG_FIFO_WATERMARK 0x0060 28362306a36Sopenharmony_ci#define INV_ICM42600_FIFO_WATERMARK_VAL(_wm) \ 28462306a36Sopenharmony_ci cpu_to_le16((_wm) & GENMASK(11, 0)) 28562306a36Sopenharmony_ci/* FIFO is 2048 bytes, let 12 samples for reading latency */ 28662306a36Sopenharmony_ci#define INV_ICM42600_FIFO_WATERMARK_MAX (2048 - 12 * 16) 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_ci#define INV_ICM42600_REG_INT_CONFIG1 0x0064 28962306a36Sopenharmony_ci#define INV_ICM42600_INT_CONFIG1_TPULSE_DURATION BIT(6) 29062306a36Sopenharmony_ci#define INV_ICM42600_INT_CONFIG1_TDEASSERT_DISABLE BIT(5) 29162306a36Sopenharmony_ci#define INV_ICM42600_INT_CONFIG1_ASYNC_RESET BIT(4) 29262306a36Sopenharmony_ci 29362306a36Sopenharmony_ci#define INV_ICM42600_REG_INT_SOURCE0 0x0065 29462306a36Sopenharmony_ci#define INV_ICM42600_INT_SOURCE0_UI_FSYNC_INT1_EN BIT(6) 29562306a36Sopenharmony_ci#define INV_ICM42600_INT_SOURCE0_PLL_RDY_INT1_EN BIT(5) 29662306a36Sopenharmony_ci#define INV_ICM42600_INT_SOURCE0_RESET_DONE_INT1_EN BIT(4) 29762306a36Sopenharmony_ci#define INV_ICM42600_INT_SOURCE0_UI_DRDY_INT1_EN BIT(3) 29862306a36Sopenharmony_ci#define INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN BIT(2) 29962306a36Sopenharmony_ci#define INV_ICM42600_INT_SOURCE0_FIFO_FULL_INT1_EN BIT(1) 30062306a36Sopenharmony_ci#define INV_ICM42600_INT_SOURCE0_UI_AGC_RDY_INT1_EN BIT(0) 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ci#define INV_ICM42600_REG_WHOAMI 0x0075 30362306a36Sopenharmony_ci#define INV_ICM42600_WHOAMI_ICM42600 0x40 30462306a36Sopenharmony_ci#define INV_ICM42600_WHOAMI_ICM42602 0x41 30562306a36Sopenharmony_ci#define INV_ICM42600_WHOAMI_ICM42605 0x42 30662306a36Sopenharmony_ci#define INV_ICM42600_WHOAMI_ICM42622 0x46 30762306a36Sopenharmony_ci#define INV_ICM42600_WHOAMI_ICM42631 0x5C 30862306a36Sopenharmony_ci 30962306a36Sopenharmony_ci/* User bank 1 (MSB 0x10) */ 31062306a36Sopenharmony_ci#define INV_ICM42600_REG_SENSOR_CONFIG0 0x1003 31162306a36Sopenharmony_ci#define INV_ICM42600_SENSOR_CONFIG0_ZG_DISABLE BIT(5) 31262306a36Sopenharmony_ci#define INV_ICM42600_SENSOR_CONFIG0_YG_DISABLE BIT(4) 31362306a36Sopenharmony_ci#define INV_ICM42600_SENSOR_CONFIG0_XG_DISABLE BIT(3) 31462306a36Sopenharmony_ci#define INV_ICM42600_SENSOR_CONFIG0_ZA_DISABLE BIT(2) 31562306a36Sopenharmony_ci#define INV_ICM42600_SENSOR_CONFIG0_YA_DISABLE BIT(1) 31662306a36Sopenharmony_ci#define INV_ICM42600_SENSOR_CONFIG0_XA_DISABLE BIT(0) 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_ci/* Timestamp value is 20 bits (3 registers) in little-endian */ 31962306a36Sopenharmony_ci#define INV_ICM42600_REG_TMSTVAL 0x1062 32062306a36Sopenharmony_ci#define INV_ICM42600_TMSTVAL_MASK GENMASK(19, 0) 32162306a36Sopenharmony_ci 32262306a36Sopenharmony_ci#define INV_ICM42600_REG_INTF_CONFIG4 0x107A 32362306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG4_I3C_BUS_ONLY BIT(6) 32462306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG4_SPI_AP_4WIRE BIT(1) 32562306a36Sopenharmony_ci 32662306a36Sopenharmony_ci#define INV_ICM42600_REG_INTF_CONFIG6 0x107C 32762306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG6_MASK GENMASK(4, 0) 32862306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG6_I3C_EN BIT(4) 32962306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG6_I3C_IBI_BYTE_EN BIT(3) 33062306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG6_I3C_IBI_EN BIT(2) 33162306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG6_I3C_DDR_EN BIT(1) 33262306a36Sopenharmony_ci#define INV_ICM42600_INTF_CONFIG6_I3C_SDR_EN BIT(0) 33362306a36Sopenharmony_ci 33462306a36Sopenharmony_ci/* User bank 4 (MSB 0x40) */ 33562306a36Sopenharmony_ci#define INV_ICM42600_REG_INT_SOURCE8 0x404F 33662306a36Sopenharmony_ci#define INV_ICM42600_INT_SOURCE8_FSYNC_IBI_EN BIT(5) 33762306a36Sopenharmony_ci#define INV_ICM42600_INT_SOURCE8_PLL_RDY_IBI_EN BIT(4) 33862306a36Sopenharmony_ci#define INV_ICM42600_INT_SOURCE8_UI_DRDY_IBI_EN BIT(3) 33962306a36Sopenharmony_ci#define INV_ICM42600_INT_SOURCE8_FIFO_THS_IBI_EN BIT(2) 34062306a36Sopenharmony_ci#define INV_ICM42600_INT_SOURCE8_FIFO_FULL_IBI_EN BIT(1) 34162306a36Sopenharmony_ci#define INV_ICM42600_INT_SOURCE8_AGC_RDY_IBI_EN BIT(0) 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER0 0x4077 34462306a36Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER1 0x4078 34562306a36Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER2 0x4079 34662306a36Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER3 0x407A 34762306a36Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER4 0x407B 34862306a36Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER5 0x407C 34962306a36Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER6 0x407D 35062306a36Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER7 0x407E 35162306a36Sopenharmony_ci#define INV_ICM42600_REG_OFFSET_USER8 0x407F 35262306a36Sopenharmony_ci 35362306a36Sopenharmony_ci/* Sleep times required by the driver */ 35462306a36Sopenharmony_ci#define INV_ICM42600_POWER_UP_TIME_MS 100 35562306a36Sopenharmony_ci#define INV_ICM42600_RESET_TIME_MS 1 35662306a36Sopenharmony_ci#define INV_ICM42600_ACCEL_STARTUP_TIME_MS 20 35762306a36Sopenharmony_ci#define INV_ICM42600_GYRO_STARTUP_TIME_MS 60 35862306a36Sopenharmony_ci#define INV_ICM42600_GYRO_STOP_TIME_MS 150 35962306a36Sopenharmony_ci#define INV_ICM42600_TEMP_STARTUP_TIME_MS 14 36062306a36Sopenharmony_ci#define INV_ICM42600_SUSPEND_DELAY_MS 2000 36162306a36Sopenharmony_ci 36262306a36Sopenharmony_citypedef int (*inv_icm42600_bus_setup)(struct inv_icm42600_state *); 36362306a36Sopenharmony_ci 36462306a36Sopenharmony_ciextern const struct regmap_config inv_icm42600_regmap_config; 36562306a36Sopenharmony_ciextern const struct dev_pm_ops inv_icm42600_pm_ops; 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_ciconst struct iio_mount_matrix * 36862306a36Sopenharmony_ciinv_icm42600_get_mount_matrix(const struct iio_dev *indio_dev, 36962306a36Sopenharmony_ci const struct iio_chan_spec *chan); 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_ciuint32_t inv_icm42600_odr_to_period(enum inv_icm42600_odr odr); 37262306a36Sopenharmony_ci 37362306a36Sopenharmony_ciint inv_icm42600_set_accel_conf(struct inv_icm42600_state *st, 37462306a36Sopenharmony_ci struct inv_icm42600_sensor_conf *conf, 37562306a36Sopenharmony_ci unsigned int *sleep_ms); 37662306a36Sopenharmony_ci 37762306a36Sopenharmony_ciint inv_icm42600_set_gyro_conf(struct inv_icm42600_state *st, 37862306a36Sopenharmony_ci struct inv_icm42600_sensor_conf *conf, 37962306a36Sopenharmony_ci unsigned int *sleep_ms); 38062306a36Sopenharmony_ci 38162306a36Sopenharmony_ciint inv_icm42600_set_temp_conf(struct inv_icm42600_state *st, bool enable, 38262306a36Sopenharmony_ci unsigned int *sleep_ms); 38362306a36Sopenharmony_ci 38462306a36Sopenharmony_ciint inv_icm42600_debugfs_reg(struct iio_dev *indio_dev, unsigned int reg, 38562306a36Sopenharmony_ci unsigned int writeval, unsigned int *readval); 38662306a36Sopenharmony_ci 38762306a36Sopenharmony_ciint inv_icm42600_core_probe(struct regmap *regmap, int chip, int irq, 38862306a36Sopenharmony_ci inv_icm42600_bus_setup bus_setup); 38962306a36Sopenharmony_ci 39062306a36Sopenharmony_cistruct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st); 39162306a36Sopenharmony_ci 39262306a36Sopenharmony_ciint inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev); 39362306a36Sopenharmony_ci 39462306a36Sopenharmony_cistruct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st); 39562306a36Sopenharmony_ci 39662306a36Sopenharmony_ciint inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev); 39762306a36Sopenharmony_ci 39862306a36Sopenharmony_ci#endif 399