bma400.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Register constants and other forward declarations needed by the bma400
  4. * sources.
  5. *
  6. * Copyright 2019 Dan Robertson <[email protected]>
  7. */
  8. #ifndef _BMA400_H_
  9. #define _BMA400_H_
  10. #include <linux/bits.h>
  11. #include <linux/regmap.h>
  12. /*
  13. * Read-Only Registers
  14. */
  15. /* Status and ID registers */
  16. #define BMA400_CHIP_ID_REG 0x00
  17. #define BMA400_ERR_REG 0x02
  18. #define BMA400_STATUS_REG 0x03
  19. /* Acceleration registers */
  20. #define BMA400_X_AXIS_LSB_REG 0x04
  21. #define BMA400_X_AXIS_MSB_REG 0x05
  22. #define BMA400_Y_AXIS_LSB_REG 0x06
  23. #define BMA400_Y_AXIS_MSB_REG 0x07
  24. #define BMA400_Z_AXIS_LSB_REG 0x08
  25. #define BMA400_Z_AXIS_MSB_REG 0x09
  26. /* Sensor time registers */
  27. #define BMA400_SENSOR_TIME0 0x0a
  28. #define BMA400_SENSOR_TIME1 0x0b
  29. #define BMA400_SENSOR_TIME2 0x0c
  30. /* Event and interrupt registers */
  31. #define BMA400_EVENT_REG 0x0d
  32. #define BMA400_INT_STAT0_REG 0x0e
  33. #define BMA400_INT_STAT1_REG 0x0f
  34. #define BMA400_INT_STAT2_REG 0x10
  35. #define BMA400_INT12_MAP_REG 0x23
  36. #define BMA400_INT_ENG_OVRUN_MSK BIT(4)
  37. /* Temperature register */
  38. #define BMA400_TEMP_DATA_REG 0x11
  39. /* FIFO length and data registers */
  40. #define BMA400_FIFO_LENGTH0_REG 0x12
  41. #define BMA400_FIFO_LENGTH1_REG 0x13
  42. #define BMA400_FIFO_DATA_REG 0x14
  43. /* Step count registers */
  44. #define BMA400_STEP_CNT0_REG 0x15
  45. #define BMA400_STEP_CNT1_REG 0x16
  46. #define BMA400_STEP_CNT3_REG 0x17
  47. #define BMA400_STEP_STAT_REG 0x18
  48. #define BMA400_STEP_INT_MSK BIT(0)
  49. #define BMA400_STEP_RAW_LEN 0x03
  50. #define BMA400_STEP_STAT_MASK GENMASK(9, 8)
  51. /*
  52. * Read-write configuration registers
  53. */
  54. #define BMA400_ACC_CONFIG0_REG 0x19
  55. #define BMA400_ACC_CONFIG1_REG 0x1a
  56. #define BMA400_ACC_CONFIG2_REG 0x1b
  57. #define BMA400_CMD_REG 0x7e
  58. /* Interrupt registers */
  59. #define BMA400_INT_CONFIG0_REG 0x1f
  60. #define BMA400_INT_CONFIG1_REG 0x20
  61. #define BMA400_INT1_MAP_REG 0x21
  62. #define BMA400_INT_IO_CTRL_REG 0x24
  63. #define BMA400_INT_DRDY_MSK BIT(7)
  64. /* Chip ID of BMA 400 devices found in the chip ID register. */
  65. #define BMA400_ID_REG_VAL 0x90
  66. #define BMA400_LP_OSR_SHIFT 5
  67. #define BMA400_NP_OSR_SHIFT 4
  68. #define BMA400_SCALE_SHIFT 6
  69. #define BMA400_TWO_BITS_MASK GENMASK(1, 0)
  70. #define BMA400_LP_OSR_MASK GENMASK(6, 5)
  71. #define BMA400_NP_OSR_MASK GENMASK(5, 4)
  72. #define BMA400_ACC_ODR_MASK GENMASK(3, 0)
  73. #define BMA400_ACC_SCALE_MASK GENMASK(7, 6)
  74. #define BMA400_ACC_ODR_MIN_RAW 0x05
  75. #define BMA400_ACC_ODR_LP_RAW 0x06
  76. #define BMA400_ACC_ODR_MAX_RAW 0x0b
  77. #define BMA400_ACC_ODR_MAX_HZ 800
  78. #define BMA400_ACC_ODR_MIN_WHOLE_HZ 25
  79. #define BMA400_ACC_ODR_MIN_HZ 12
  80. /* Generic interrupts register */
  81. #define BMA400_GEN1INT_CONFIG0 0x3f
  82. #define BMA400_GEN2INT_CONFIG0 0x4A
  83. #define BMA400_GEN_CONFIG1_OFF 0x01
  84. #define BMA400_GEN_CONFIG2_OFF 0x02
  85. #define BMA400_GEN_CONFIG3_OFF 0x03
  86. #define BMA400_GEN_CONFIG31_OFF 0x04
  87. #define BMA400_INT_GEN1_MSK BIT(2)
  88. #define BMA400_INT_GEN2_MSK BIT(3)
  89. #define BMA400_GEN_HYST_MSK GENMASK(1, 0)
  90. /* TAP config registers */
  91. #define BMA400_TAP_CONFIG 0x57
  92. #define BMA400_TAP_CONFIG1 0x58
  93. #define BMA400_S_TAP_MSK BIT(2)
  94. #define BMA400_D_TAP_MSK BIT(3)
  95. #define BMA400_INT_S_TAP_MSK BIT(10)
  96. #define BMA400_INT_D_TAP_MSK BIT(11)
  97. #define BMA400_TAP_SEN_MSK GENMASK(2, 0)
  98. #define BMA400_TAP_TICSTH_MSK GENMASK(1, 0)
  99. #define BMA400_TAP_QUIET_MSK GENMASK(3, 2)
  100. #define BMA400_TAP_QUIETDT_MSK GENMASK(5, 4)
  101. #define BMA400_TAP_TIM_LIST_LEN 4
  102. /*
  103. * BMA400_SCALE_MIN macro value represents m/s^2 for 1 LSB before
  104. * converting to micro values for +-2g range.
  105. *
  106. * For +-2g - 1 LSB = 0.976562 milli g = 0.009576 m/s^2
  107. * For +-4g - 1 LSB = 1.953125 milli g = 0.019153 m/s^2
  108. * For +-16g - 1 LSB = 7.8125 milli g = 0.076614 m/s^2
  109. *
  110. * The raw value which is used to select the different ranges is determined
  111. * by the first bit set position from the scale value, so BMA400_SCALE_MIN
  112. * should be odd.
  113. *
  114. * Scale values for +-2g, +-4g, +-8g and +-16g are populated into bma400_scales
  115. * array by left shifting BMA400_SCALE_MIN.
  116. * e.g.:
  117. * To select +-2g = 9577 << 0 = raw value to write is 0.
  118. * To select +-8g = 9577 << 2 = raw value to write is 2.
  119. * To select +-16g = 9577 << 3 = raw value to write is 3.
  120. */
  121. #define BMA400_SCALE_MIN 9577
  122. #define BMA400_SCALE_MAX 76617
  123. #define BMA400_NUM_REGULATORS 2
  124. #define BMA400_VDD_REGULATOR 0
  125. #define BMA400_VDDIO_REGULATOR 1
  126. extern const struct regmap_config bma400_regmap_config;
  127. int bma400_probe(struct device *dev, struct regmap *regmap, int irq,
  128. const char *name);
  129. #endif