0001
0002
0003
0004
0005
0006 #ifndef INV_ICM42600_H_
0007 #define INV_ICM42600_H_
0008
0009 #include <linux/bits.h>
0010 #include <linux/bitfield.h>
0011 #include <linux/regmap.h>
0012 #include <linux/mutex.h>
0013 #include <linux/regulator/consumer.h>
0014 #include <linux/pm.h>
0015 #include <linux/iio/iio.h>
0016
0017 #include "inv_icm42600_buffer.h"
0018
0019 enum inv_icm42600_chip {
0020 INV_CHIP_INVALID,
0021 INV_CHIP_ICM42600,
0022 INV_CHIP_ICM42602,
0023 INV_CHIP_ICM42605,
0024 INV_CHIP_ICM42622,
0025 INV_CHIP_NB,
0026 };
0027
0028
0029 enum inv_icm42600_slew_rate {
0030 INV_ICM42600_SLEW_RATE_20_60NS,
0031 INV_ICM42600_SLEW_RATE_12_36NS,
0032 INV_ICM42600_SLEW_RATE_6_18NS,
0033 INV_ICM42600_SLEW_RATE_4_12NS,
0034 INV_ICM42600_SLEW_RATE_2_6NS,
0035 INV_ICM42600_SLEW_RATE_INF_2NS,
0036 };
0037
0038 enum inv_icm42600_sensor_mode {
0039 INV_ICM42600_SENSOR_MODE_OFF,
0040 INV_ICM42600_SENSOR_MODE_STANDBY,
0041 INV_ICM42600_SENSOR_MODE_LOW_POWER,
0042 INV_ICM42600_SENSOR_MODE_LOW_NOISE,
0043 INV_ICM42600_SENSOR_MODE_NB,
0044 };
0045
0046
0047 enum inv_icm42600_gyro_fs {
0048 INV_ICM42600_GYRO_FS_2000DPS,
0049 INV_ICM42600_GYRO_FS_1000DPS,
0050 INV_ICM42600_GYRO_FS_500DPS,
0051 INV_ICM42600_GYRO_FS_250DPS,
0052 INV_ICM42600_GYRO_FS_125DPS,
0053 INV_ICM42600_GYRO_FS_62_5DPS,
0054 INV_ICM42600_GYRO_FS_31_25DPS,
0055 INV_ICM42600_GYRO_FS_15_625DPS,
0056 INV_ICM42600_GYRO_FS_NB,
0057 };
0058
0059
0060 enum inv_icm42600_accel_fs {
0061 INV_ICM42600_ACCEL_FS_16G,
0062 INV_ICM42600_ACCEL_FS_8G,
0063 INV_ICM42600_ACCEL_FS_4G,
0064 INV_ICM42600_ACCEL_FS_2G,
0065 INV_ICM42600_ACCEL_FS_NB,
0066 };
0067
0068
0069 enum inv_icm42600_odr {
0070 INV_ICM42600_ODR_8KHZ_LN = 3,
0071 INV_ICM42600_ODR_4KHZ_LN,
0072 INV_ICM42600_ODR_2KHZ_LN,
0073 INV_ICM42600_ODR_1KHZ_LN,
0074 INV_ICM42600_ODR_200HZ,
0075 INV_ICM42600_ODR_100HZ,
0076 INV_ICM42600_ODR_50HZ,
0077 INV_ICM42600_ODR_25HZ,
0078 INV_ICM42600_ODR_12_5HZ,
0079 INV_ICM42600_ODR_6_25HZ_LP,
0080 INV_ICM42600_ODR_3_125HZ_LP,
0081 INV_ICM42600_ODR_1_5625HZ_LP,
0082 INV_ICM42600_ODR_500HZ,
0083 INV_ICM42600_ODR_NB,
0084 };
0085
0086 enum inv_icm42600_filter {
0087
0088 INV_ICM42600_FILTER_BW_ODR_DIV_2,
0089
0090
0091 INV_ICM42600_FILTER_AVG_1X = 1,
0092 INV_ICM42600_FILTER_AVG_16X = 6,
0093 };
0094
0095 struct inv_icm42600_sensor_conf {
0096 int mode;
0097 int fs;
0098 int odr;
0099 int filter;
0100 };
0101 #define INV_ICM42600_SENSOR_CONF_INIT {-1, -1, -1, -1}
0102
0103 struct inv_icm42600_conf {
0104 struct inv_icm42600_sensor_conf gyro;
0105 struct inv_icm42600_sensor_conf accel;
0106 bool temp_en;
0107 };
0108
0109 struct inv_icm42600_suspended {
0110 enum inv_icm42600_sensor_mode gyro;
0111 enum inv_icm42600_sensor_mode accel;
0112 bool temp;
0113 };
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132 struct inv_icm42600_state {
0133 struct mutex lock;
0134 enum inv_icm42600_chip chip;
0135 const char *name;
0136 struct regmap *map;
0137 struct regulator *vdd_supply;
0138 struct regulator *vddio_supply;
0139 struct iio_mount_matrix orientation;
0140 struct inv_icm42600_conf conf;
0141 struct inv_icm42600_suspended suspended;
0142 struct iio_dev *indio_gyro;
0143 struct iio_dev *indio_accel;
0144 uint8_t buffer[2] __aligned(IIO_DMA_MINALIGN);
0145 struct inv_icm42600_fifo fifo;
0146 struct {
0147 int64_t gyro;
0148 int64_t accel;
0149 } timestamp;
0150 };
0151
0152
0153
0154
0155 #define INV_ICM42600_REG_BANK_SEL 0x76
0156 #define INV_ICM42600_BANK_SEL_MASK GENMASK(2, 0)
0157
0158
0159 #define INV_ICM42600_REG_DEVICE_CONFIG 0x0011
0160 #define INV_ICM42600_DEVICE_CONFIG_SOFT_RESET BIT(0)
0161
0162 #define INV_ICM42600_REG_DRIVE_CONFIG 0x0013
0163 #define INV_ICM42600_DRIVE_CONFIG_I2C_MASK GENMASK(5, 3)
0164 #define INV_ICM42600_DRIVE_CONFIG_I2C(_rate) \
0165 FIELD_PREP(INV_ICM42600_DRIVE_CONFIG_I2C_MASK, (_rate))
0166 #define INV_ICM42600_DRIVE_CONFIG_SPI_MASK GENMASK(2, 0)
0167 #define INV_ICM42600_DRIVE_CONFIG_SPI(_rate) \
0168 FIELD_PREP(INV_ICM42600_DRIVE_CONFIG_SPI_MASK, (_rate))
0169
0170 #define INV_ICM42600_REG_INT_CONFIG 0x0014
0171 #define INV_ICM42600_INT_CONFIG_INT2_LATCHED BIT(5)
0172 #define INV_ICM42600_INT_CONFIG_INT2_PUSH_PULL BIT(4)
0173 #define INV_ICM42600_INT_CONFIG_INT2_ACTIVE_HIGH BIT(3)
0174 #define INV_ICM42600_INT_CONFIG_INT2_ACTIVE_LOW 0x00
0175 #define INV_ICM42600_INT_CONFIG_INT1_LATCHED BIT(2)
0176 #define INV_ICM42600_INT_CONFIG_INT1_PUSH_PULL BIT(1)
0177 #define INV_ICM42600_INT_CONFIG_INT1_ACTIVE_HIGH BIT(0)
0178 #define INV_ICM42600_INT_CONFIG_INT1_ACTIVE_LOW 0x00
0179
0180 #define INV_ICM42600_REG_FIFO_CONFIG 0x0016
0181 #define INV_ICM42600_FIFO_CONFIG_MASK GENMASK(7, 6)
0182 #define INV_ICM42600_FIFO_CONFIG_BYPASS \
0183 FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 0)
0184 #define INV_ICM42600_FIFO_CONFIG_STREAM \
0185 FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 1)
0186 #define INV_ICM42600_FIFO_CONFIG_STOP_ON_FULL \
0187 FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 2)
0188
0189
0190 #define INV_ICM42600_REG_TEMP_DATA 0x001D
0191 #define INV_ICM42600_REG_ACCEL_DATA_X 0x001F
0192 #define INV_ICM42600_REG_ACCEL_DATA_Y 0x0021
0193 #define INV_ICM42600_REG_ACCEL_DATA_Z 0x0023
0194 #define INV_ICM42600_REG_GYRO_DATA_X 0x0025
0195 #define INV_ICM42600_REG_GYRO_DATA_Y 0x0027
0196 #define INV_ICM42600_REG_GYRO_DATA_Z 0x0029
0197 #define INV_ICM42600_DATA_INVALID -32768
0198
0199 #define INV_ICM42600_REG_INT_STATUS 0x002D
0200 #define INV_ICM42600_INT_STATUS_UI_FSYNC BIT(6)
0201 #define INV_ICM42600_INT_STATUS_PLL_RDY BIT(5)
0202 #define INV_ICM42600_INT_STATUS_RESET_DONE BIT(4)
0203 #define INV_ICM42600_INT_STATUS_DATA_RDY BIT(3)
0204 #define INV_ICM42600_INT_STATUS_FIFO_THS BIT(2)
0205 #define INV_ICM42600_INT_STATUS_FIFO_FULL BIT(1)
0206 #define INV_ICM42600_INT_STATUS_AGC_RDY BIT(0)
0207
0208
0209
0210
0211
0212
0213 #define INV_ICM42600_REG_FIFO_COUNT 0x002E
0214 #define INV_ICM42600_REG_FIFO_DATA 0x0030
0215
0216 #define INV_ICM42600_REG_SIGNAL_PATH_RESET 0x004B
0217 #define INV_ICM42600_SIGNAL_PATH_RESET_DMP_INIT_EN BIT(6)
0218 #define INV_ICM42600_SIGNAL_PATH_RESET_DMP_MEM_RESET BIT(5)
0219 #define INV_ICM42600_SIGNAL_PATH_RESET_RESET BIT(3)
0220 #define INV_ICM42600_SIGNAL_PATH_RESET_TMST_STROBE BIT(2)
0221 #define INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH BIT(1)
0222
0223
0224 #define INV_ICM42600_REG_INTF_CONFIG0 0x004C
0225 #define INV_ICM42600_INTF_CONFIG0_FIFO_HOLD_LAST_DATA BIT(7)
0226 #define INV_ICM42600_INTF_CONFIG0_FIFO_COUNT_REC BIT(6)
0227 #define INV_ICM42600_INTF_CONFIG0_FIFO_COUNT_ENDIAN BIT(5)
0228 #define INV_ICM42600_INTF_CONFIG0_SENSOR_DATA_ENDIAN BIT(4)
0229 #define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK GENMASK(1, 0)
0230 #define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_SPI_DIS \
0231 FIELD_PREP(INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK, 2)
0232 #define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_I2C_DIS \
0233 FIELD_PREP(INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK, 3)
0234
0235 #define INV_ICM42600_REG_INTF_CONFIG1 0x004D
0236 #define INV_ICM42600_INTF_CONFIG1_ACCEL_LP_CLK_RC BIT(3)
0237
0238 #define INV_ICM42600_REG_PWR_MGMT0 0x004E
0239 #define INV_ICM42600_PWR_MGMT0_TEMP_DIS BIT(5)
0240 #define INV_ICM42600_PWR_MGMT0_IDLE BIT(4)
0241 #define INV_ICM42600_PWR_MGMT0_GYRO(_mode) \
0242 FIELD_PREP(GENMASK(3, 2), (_mode))
0243 #define INV_ICM42600_PWR_MGMT0_ACCEL(_mode) \
0244 FIELD_PREP(GENMASK(1, 0), (_mode))
0245
0246 #define INV_ICM42600_REG_GYRO_CONFIG0 0x004F
0247 #define INV_ICM42600_GYRO_CONFIG0_FS(_fs) \
0248 FIELD_PREP(GENMASK(7, 5), (_fs))
0249 #define INV_ICM42600_GYRO_CONFIG0_ODR(_odr) \
0250 FIELD_PREP(GENMASK(3, 0), (_odr))
0251
0252 #define INV_ICM42600_REG_ACCEL_CONFIG0 0x0050
0253 #define INV_ICM42600_ACCEL_CONFIG0_FS(_fs) \
0254 FIELD_PREP(GENMASK(7, 5), (_fs))
0255 #define INV_ICM42600_ACCEL_CONFIG0_ODR(_odr) \
0256 FIELD_PREP(GENMASK(3, 0), (_odr))
0257
0258 #define INV_ICM42600_REG_GYRO_ACCEL_CONFIG0 0x0052
0259 #define INV_ICM42600_GYRO_ACCEL_CONFIG0_ACCEL_FILT(_f) \
0260 FIELD_PREP(GENMASK(7, 4), (_f))
0261 #define INV_ICM42600_GYRO_ACCEL_CONFIG0_GYRO_FILT(_f) \
0262 FIELD_PREP(GENMASK(3, 0), (_f))
0263
0264 #define INV_ICM42600_REG_TMST_CONFIG 0x0054
0265 #define INV_ICM42600_TMST_CONFIG_MASK GENMASK(4, 0)
0266 #define INV_ICM42600_TMST_CONFIG_TMST_TO_REGS_EN BIT(4)
0267 #define INV_ICM42600_TMST_CONFIG_TMST_RES_16US BIT(3)
0268 #define INV_ICM42600_TMST_CONFIG_TMST_DELTA_EN BIT(2)
0269 #define INV_ICM42600_TMST_CONFIG_TMST_FSYNC_EN BIT(1)
0270 #define INV_ICM42600_TMST_CONFIG_TMST_EN BIT(0)
0271
0272 #define INV_ICM42600_REG_FIFO_CONFIG1 0x005F
0273 #define INV_ICM42600_FIFO_CONFIG1_RESUME_PARTIAL_RD BIT(6)
0274 #define INV_ICM42600_FIFO_CONFIG1_WM_GT_TH BIT(5)
0275 #define INV_ICM42600_FIFO_CONFIG1_TMST_FSYNC_EN BIT(3)
0276 #define INV_ICM42600_FIFO_CONFIG1_TEMP_EN BIT(2)
0277 #define INV_ICM42600_FIFO_CONFIG1_GYRO_EN BIT(1)
0278 #define INV_ICM42600_FIFO_CONFIG1_ACCEL_EN BIT(0)
0279
0280
0281 #define INV_ICM42600_REG_FIFO_WATERMARK 0x0060
0282 #define INV_ICM42600_FIFO_WATERMARK_VAL(_wm) \
0283 cpu_to_le16((_wm) & GENMASK(11, 0))
0284
0285 #define INV_ICM42600_FIFO_WATERMARK_MAX (2048 - 12 * 16)
0286
0287 #define INV_ICM42600_REG_INT_CONFIG1 0x0064
0288 #define INV_ICM42600_INT_CONFIG1_TPULSE_DURATION BIT(6)
0289 #define INV_ICM42600_INT_CONFIG1_TDEASSERT_DISABLE BIT(5)
0290 #define INV_ICM42600_INT_CONFIG1_ASYNC_RESET BIT(4)
0291
0292 #define INV_ICM42600_REG_INT_SOURCE0 0x0065
0293 #define INV_ICM42600_INT_SOURCE0_UI_FSYNC_INT1_EN BIT(6)
0294 #define INV_ICM42600_INT_SOURCE0_PLL_RDY_INT1_EN BIT(5)
0295 #define INV_ICM42600_INT_SOURCE0_RESET_DONE_INT1_EN BIT(4)
0296 #define INV_ICM42600_INT_SOURCE0_UI_DRDY_INT1_EN BIT(3)
0297 #define INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN BIT(2)
0298 #define INV_ICM42600_INT_SOURCE0_FIFO_FULL_INT1_EN BIT(1)
0299 #define INV_ICM42600_INT_SOURCE0_UI_AGC_RDY_INT1_EN BIT(0)
0300
0301 #define INV_ICM42600_REG_WHOAMI 0x0075
0302 #define INV_ICM42600_WHOAMI_ICM42600 0x40
0303 #define INV_ICM42600_WHOAMI_ICM42602 0x41
0304 #define INV_ICM42600_WHOAMI_ICM42605 0x42
0305 #define INV_ICM42600_WHOAMI_ICM42622 0x46
0306
0307
0308 #define INV_ICM42600_REG_SENSOR_CONFIG0 0x1003
0309 #define INV_ICM42600_SENSOR_CONFIG0_ZG_DISABLE BIT(5)
0310 #define INV_ICM42600_SENSOR_CONFIG0_YG_DISABLE BIT(4)
0311 #define INV_ICM42600_SENSOR_CONFIG0_XG_DISABLE BIT(3)
0312 #define INV_ICM42600_SENSOR_CONFIG0_ZA_DISABLE BIT(2)
0313 #define INV_ICM42600_SENSOR_CONFIG0_YA_DISABLE BIT(1)
0314 #define INV_ICM42600_SENSOR_CONFIG0_XA_DISABLE BIT(0)
0315
0316
0317 #define INV_ICM42600_REG_TMSTVAL 0x1062
0318 #define INV_ICM42600_TMSTVAL_MASK GENMASK(19, 0)
0319
0320 #define INV_ICM42600_REG_INTF_CONFIG4 0x107A
0321 #define INV_ICM42600_INTF_CONFIG4_I3C_BUS_ONLY BIT(6)
0322 #define INV_ICM42600_INTF_CONFIG4_SPI_AP_4WIRE BIT(1)
0323
0324 #define INV_ICM42600_REG_INTF_CONFIG6 0x107C
0325 #define INV_ICM42600_INTF_CONFIG6_MASK GENMASK(4, 0)
0326 #define INV_ICM42600_INTF_CONFIG6_I3C_EN BIT(4)
0327 #define INV_ICM42600_INTF_CONFIG6_I3C_IBI_BYTE_EN BIT(3)
0328 #define INV_ICM42600_INTF_CONFIG6_I3C_IBI_EN BIT(2)
0329 #define INV_ICM42600_INTF_CONFIG6_I3C_DDR_EN BIT(1)
0330 #define INV_ICM42600_INTF_CONFIG6_I3C_SDR_EN BIT(0)
0331
0332
0333 #define INV_ICM42600_REG_INT_SOURCE8 0x404F
0334 #define INV_ICM42600_INT_SOURCE8_FSYNC_IBI_EN BIT(5)
0335 #define INV_ICM42600_INT_SOURCE8_PLL_RDY_IBI_EN BIT(4)
0336 #define INV_ICM42600_INT_SOURCE8_UI_DRDY_IBI_EN BIT(3)
0337 #define INV_ICM42600_INT_SOURCE8_FIFO_THS_IBI_EN BIT(2)
0338 #define INV_ICM42600_INT_SOURCE8_FIFO_FULL_IBI_EN BIT(1)
0339 #define INV_ICM42600_INT_SOURCE8_AGC_RDY_IBI_EN BIT(0)
0340
0341 #define INV_ICM42600_REG_OFFSET_USER0 0x4077
0342 #define INV_ICM42600_REG_OFFSET_USER1 0x4078
0343 #define INV_ICM42600_REG_OFFSET_USER2 0x4079
0344 #define INV_ICM42600_REG_OFFSET_USER3 0x407A
0345 #define INV_ICM42600_REG_OFFSET_USER4 0x407B
0346 #define INV_ICM42600_REG_OFFSET_USER5 0x407C
0347 #define INV_ICM42600_REG_OFFSET_USER6 0x407D
0348 #define INV_ICM42600_REG_OFFSET_USER7 0x407E
0349 #define INV_ICM42600_REG_OFFSET_USER8 0x407F
0350
0351
0352 #define INV_ICM42600_POWER_UP_TIME_MS 100
0353 #define INV_ICM42600_RESET_TIME_MS 1
0354 #define INV_ICM42600_ACCEL_STARTUP_TIME_MS 20
0355 #define INV_ICM42600_GYRO_STARTUP_TIME_MS 60
0356 #define INV_ICM42600_GYRO_STOP_TIME_MS 150
0357 #define INV_ICM42600_TEMP_STARTUP_TIME_MS 14
0358 #define INV_ICM42600_SUSPEND_DELAY_MS 2000
0359
0360 typedef int (*inv_icm42600_bus_setup)(struct inv_icm42600_state *);
0361
0362 extern const struct regmap_config inv_icm42600_regmap_config;
0363 extern const struct dev_pm_ops inv_icm42600_pm_ops;
0364
0365 const struct iio_mount_matrix *
0366 inv_icm42600_get_mount_matrix(const struct iio_dev *indio_dev,
0367 const struct iio_chan_spec *chan);
0368
0369 uint32_t inv_icm42600_odr_to_period(enum inv_icm42600_odr odr);
0370
0371 int inv_icm42600_set_accel_conf(struct inv_icm42600_state *st,
0372 struct inv_icm42600_sensor_conf *conf,
0373 unsigned int *sleep_ms);
0374
0375 int inv_icm42600_set_gyro_conf(struct inv_icm42600_state *st,
0376 struct inv_icm42600_sensor_conf *conf,
0377 unsigned int *sleep_ms);
0378
0379 int inv_icm42600_set_temp_conf(struct inv_icm42600_state *st, bool enable,
0380 unsigned int *sleep_ms);
0381
0382 int inv_icm42600_debugfs_reg(struct iio_dev *indio_dev, unsigned int reg,
0383 unsigned int writeval, unsigned int *readval);
0384
0385 int inv_icm42600_core_probe(struct regmap *regmap, int chip, int irq,
0386 inv_icm42600_bus_setup bus_setup);
0387
0388 struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st);
0389
0390 int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev);
0391
0392 struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st);
0393
0394 int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev);
0395
0396 #endif