icm20645.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #ifndef ICM20645_H
  2. #define ICM20645_H
  3. #include <linux/ioctl.h>
  4. #define ICM20645_ACCESS_BY_GSE_I2C
  5. #ifdef ICM20645_ACCESS_BY_GSE_I2C
  6. #define ICM20645_I2C_SLAVE_ADDR (0xD2) /* mtk i2c not allow to probe two same address */
  7. #else
  8. #define ICM20645_I2C_SLAVE_ADDR 0xD0
  9. #endif
  10. #define REG_USER_CTRL 0x03
  11. #define REG_BANK_SEL 0x7F
  12. #define BANK_SEL_0 0x00
  13. #define BANK_SEL_1 0x10
  14. #define BANK_SEL_2 0x20
  15. #define BANK_SEL_3 0x30
  16. #define ICM20645_REG_LP_CONFIG 0x05
  17. #define ICM20645_REG_PWR_CTL 0x06
  18. #define ICM20645_REG_POWER_CTL2 0x07
  19. #define BIT_PWR_GYRO_STBY 0x07
  20. #define BIT_GYRO_LP_EN 0x10
  21. #define BIT_LP_EN 0x20
  22. #define BIT_CLK_PLL 0x01
  23. /* ICM20645 Register Map (Please refer to ICM20645 Specifications) */
  24. #define ICM20645_REG_DEVID 0x00
  25. #define ICM20645_REG_SAMRT_DIV 0x00
  26. #define ICM20645_REG_CFG 0x01
  27. /*set external sync, full-scale range and sample rate, low pass filter bandwidth*/
  28. #define SHIFT_GYRO_FS_SEL 1
  29. /*full-scale range and sample rate*/
  30. #define ICM20645_GYRO_CFG2 0x02
  31. #define GYRO_AVGCFG_1X 0
  32. #define GYRO_AVGCFG_2X 1
  33. #define GYRO_AVGCFG_4X 2
  34. #define GYRO_AVGCFG_8X 3
  35. #define GYRO_AVGCFG_16X 4
  36. #define GYRO_AVGCFG_32X 5
  37. #define GYRO_AVGCFG_64X 6
  38. #define GYRO_AVGCFG_128X 7
  39. #define ICM20645_REG_GYRO_XH 0x33
  40. #define GYRO_FS_SEL (0x02<<SHIFT_GYRO_FS_SEL)
  41. #define ICM20645_FS_1000 0x02
  42. #define ICM20645_FS_1000_LSB 33
  43. #define ICM20645_FS_MAX_LSB 131
  44. #define GYRO_DLPFCFG (7<<3)
  45. #define GYRO_FCHOICE 0x01
  46. #define ICM20645_SLEEP 0x40
  47. /* FIFO */
  48. #define REG_FIFO_EN 0x66
  49. #define BIT_SLV_0_FIFO_EN 1
  50. #define BIT_FIFO_EN 0x40
  51. #define REG_FIFO_EN_2 0x67
  52. #define BIT_PRS_FIFO_EN 0x20
  53. #define BIT_ACCEL_FIFO_EN 0x10
  54. #define BITS_GYRO_FIFO_EN 0x0E
  55. #define REG_FIFO_RST 0x68
  56. #define REG_FIFO_SIZE_0 0x6E
  57. #define BIT_ACCEL_FIFO_SIZE_128 0x00
  58. #define BIT_ACCEL_FIFO_SIZE_256 0x04
  59. #define BIT_ACCEL_FIFO_SIZE_512 0x08
  60. #define BIT_ACCEL_FIFO_SIZE_1024 0x0C
  61. #define BIT_GYRO_FIFO_SIZE_128 0x00
  62. #define BIT_GYRO_FIFO_SIZE_256 0x01
  63. #define BIT_GYRO_FIFO_SIZE_512 0x02
  64. #define BIT_GYRO_FIFO_SIZE_1024 0x03
  65. #define BIT_FIFO_SIZE_1024 0x01
  66. #define BIT_FIFO_SIZE_512 0x00
  67. #define BIT_FIFO_3_SIZE_256 0x40
  68. #define BIT_FIFO_3_SIZE_64 0x00
  69. #define REG_FIFO_COUNT_H 0x70
  70. #define REG_FIFO_COUNT_L 0x70
  71. #define REG_FIFO_R_W 0x72
  72. #define REG_FIFO_CFG 0x76
  73. #define BIT_MULTI_FIFO_CFG 0x01
  74. #define BIT_SINGLE_FIFO_CFG 0x00
  75. #define BIT_GYRO_FIFO_NUM (0 << 2)
  76. #define BIT_ACCEL_FIFO_NUM (1 << 2)
  77. #define BIT_PRS_FIFO_NUM 2
  78. #define BIT_EXT_FIFO_NUM 3
  79. #define MAX_5_BIT_VALUE 0x1F
  80. #define ICM20645_SUCCESS 0
  81. #define ICM20645_ERR_I2C -1
  82. #define ICM20645_ERR_STATUS -3
  83. #define ICM20645_ERR_SETUP_FAILURE -4
  84. #define ICM20645_ERR_GETGSENSORDATA -5
  85. #define ICM20645_ERR_IDENTIFICATION -6
  86. #define ICM20645_BUFSIZE 60
  87. /* 1 rad = 180/PI degree, MAX_LSB = 131, */
  88. /* 180*131/PI = 7506 */
  89. #define DEGREE_TO_RAD 7506
  90. extern int ICM20645_gse_power(void);
  91. extern int ICM20645_gse_mode(void);
  92. #ifdef ICM20645_ACCESS_BY_GSE_I2C
  93. extern int ICM20645_hwmsen_read_block(u8 addr, u8 *buf, u8 len);
  94. extern int ICM20645_hwmsen_write_block(u8 addr, u8 *buf, u8 len);
  95. #endif
  96. #endif