bma400.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 <dan@dlrobertson.com>
  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. /* Chip ID of BMA 400 devices found in the chip ID register. */
  16. #define BMA400_ID_REG_VAL 0x90
  17. /* Status and ID registers */
  18. #define BMA400_CHIP_ID_REG 0x00
  19. #define BMA400_ERR_REG 0x02
  20. #define BMA400_STATUS_REG 0x03
  21. /* Acceleration registers */
  22. #define BMA400_ACC_X_LSB_REG 0x04
  23. #define BMA400_ACC_X_MSB_REG 0x05
  24. #define BMA400_ACC_Y_LSB_REG 0x06
  25. #define BMA400_ACC_Y_MSB_REG 0x07
  26. #define BMA400_ACC_Z_LSB_REG 0x08
  27. #define BMA400_ACC_Z_MSB_REG 0x09
  28. /* Sensor time registers */
  29. #define BMA400_SENSOR_TIME0_REG 0x0a
  30. #define BMA400_SENSOR_TIME1_REG 0x0b
  31. #define BMA400_SENSOR_TIME2_REG 0x0c
  32. /* Event and interrupt registers */
  33. #define BMA400_EVENT_REG 0x0d
  34. #define BMA400_INT_STAT0_REG 0x0e
  35. #define BMA400_INT_STAT0_GEN1_MASK BIT(2)
  36. #define BMA400_INT_STAT0_GEN2_MASK BIT(3)
  37. #define BMA400_INT_STAT0_DRDY_MASK BIT(7)
  38. #define BMA400_INT_STAT1_REG 0x0f
  39. #define BMA400_INT_STAT1_STEP_INT_MASK GENMASK(9, 8)
  40. #define BMA400_INT_STAT1_S_TAP_MASK BIT(10)
  41. #define BMA400_INT_STAT1_D_TAP_MASK BIT(11)
  42. #define BMA400_INT_STAT2_REG 0x10
  43. /* Bit present in all INT_STAT registers */
  44. #define BMA400_INT_STAT_ENG_OVRRUN_MASK BIT(4)
  45. /* Temperature register */
  46. #define BMA400_TEMP_DATA_REG 0x11
  47. /* FIFO length and data registers */
  48. #define BMA400_FIFO_LENGTH0_REG 0x12
  49. #define BMA400_FIFO_LENGTH1_REG 0x13
  50. #define BMA400_FIFO_DATA_REG 0x14
  51. /* Step count registers */
  52. #define BMA400_STEP_CNT0_REG 0x15
  53. #define BMA400_STEP_CNT1_REG 0x16
  54. #define BMA400_STEP_CNT3_REG 0x17
  55. #define BMA400_STEP_STAT_REG 0x18
  56. #define BMA400_STEP_RAW_LEN 0x03
  57. /*
  58. * Read-write configuration registers
  59. */
  60. #define BMA400_ACC_CONFIG0_REG 0x19
  61. #define BMA400_ACC_CONFIG0_LP_OSR_MASK GENMASK(6, 5)
  62. #define BMA400_ACC_CONFIG1_REG 0x1a
  63. #define BMA400_ACC_CONFIG1_ODR_MASK GENMASK(3, 0)
  64. #define BMA400_ACC_CONFIG1_ODR_MIN_RAW 0x05
  65. #define BMA400_ACC_CONFIG1_ODR_LP_RAW 0x06
  66. #define BMA400_ACC_CONFIG1_ODR_MAX_RAW 0x0b
  67. #define BMA400_ACC_CONFIG1_ODR_MAX_HZ 800
  68. #define BMA400_ACC_CONFIG1_ODR_MIN_WHOLE_HZ 25
  69. #define BMA400_ACC_CONFIG1_ODR_MIN_HZ 12
  70. #define BMA400_ACC_CONFIG1_NP_OSR_MASK GENMASK(5, 4)
  71. #define BMA400_ACC_CONFIG1_ACC_RANGE_MASK GENMASK(7, 6)
  72. #define BMA400_ACC_CONFIG2_REG 0x1b
  73. /* Interrupt registers */
  74. #define BMA400_INT_CONFIG0_REG 0x1f
  75. #define BMA400_INT_CONFIG0_GEN1_MASK BIT(2)
  76. #define BMA400_INT_CONFIG0_GEN2_MASK BIT(3)
  77. #define BMA400_INT_CONFIG0_DRDY_MASK BIT(7)
  78. enum bma400_generic_intr {
  79. BMA400_GEN1_INTR = 0x1,
  80. BMA400_GEN2_INTR = 0x2,
  81. };
  82. #define BMA400_INT_CONFIG1_REG 0x20
  83. #define BMA400_INT_CONFIG1_STEP_INT_MASK BIT(0)
  84. #define BMA400_INT_CONFIG1_S_TAP_MASK BIT(2)
  85. #define BMA400_INT_CONFIG1_D_TAP_MASK BIT(3)
  86. #define BMA400_INT1_MAP_REG 0x21
  87. #define BMA400_INT12_MAP_REG 0x23
  88. #define BMA400_INT_IO_CTRL_REG 0x24
  89. #define BMA400_TWO_BITS_MASK GENMASK(1, 0)
  90. /* Generic interrupts register */
  91. #define BMA400_GENINT_CONFIG_REG_BASE 0x3f
  92. #define BMA400_NUM_GENINT_CONFIG_REGS 11
  93. #define BMA400_GENINT_CONFIG_REG(gen_intr, config_idx) \
  94. (BMA400_GENINT_CONFIG_REG_BASE + \
  95. (gen_intr - 1) * BMA400_NUM_GENINT_CONFIG_REGS + \
  96. (config_idx))
  97. #define BMA400_GENINT_CONFIG0_HYST_MASK GENMASK(1, 0)
  98. #define BMA400_GENINT_CONFIG0_REF_UPD_MODE_MASK GENMASK(3, 2)
  99. #define BMA400_GENINT_CONFIG0_DATA_SRC_MASK BIT(4)
  100. #define BMA400_GENINT_CONFIG0_X_EN_MASK BIT(5)
  101. #define BMA400_GENINT_CONFIG0_Y_EN_MASK BIT(6)
  102. #define BMA400_GENINT_CONFIG0_Z_EN_MASK BIT(7)
  103. enum bma400_accel_data_src {
  104. ACCEL_FILT1 = 0x0,
  105. ACCEL_FILT2 = 0x1,
  106. };
  107. enum bma400_ref_updt_mode {
  108. BMA400_REF_MANUAL_UPDT_MODE = 0x0,
  109. BMA400_REF_ONETIME_UPDT_MODE = 0x1,
  110. BMA400_REF_EVERYTIME_UPDT_MODE = 0x2,
  111. BMA400_REF_EVERYTIME_LP_UPDT_MODE = 0x3,
  112. };
  113. #define BMA400_GEN_CONFIG1_OFF 0x01
  114. #define BMA400_GENINT_CONFIG1_AXES_COMB_MASK BIT(0)
  115. #define BMA400_GENINT_CONFIG1_DETCT_CRIT_MASK BIT(1)
  116. enum bma400_genintr_acceleval_axescomb {
  117. BMA400_EVAL_X_OR_Y_OR_Z = 0x0,
  118. BMA400_EVAL_X_AND_Y_AND_Z = 0x1,
  119. };
  120. enum bma400_detect_criterion {
  121. BMA400_DETECT_INACTIVITY = 0x0,
  122. BMA400_DETECT_ACTIVITY = 0x1,
  123. };
  124. /* TAP config registers */
  125. #define BMA400_TAP_CONFIG_REG 0x57
  126. #define BMA400_TAP_CONFIG_SEN_MASK GENMASK(2, 0)
  127. #define BMA400_TAP_CONFIG1_REG 0x58
  128. #define BMA400_TAP_CONFIG1_TICSTH_MASK GENMASK(1, 0)
  129. #define BMA400_TAP_CONFIG1_QUIET_MASK GENMASK(3, 2)
  130. #define BMA400_TAP_CONFIG1_QUIETDT_MASK GENMASK(5, 4)
  131. #define BMA400_TAP_TIM_LIST_LEN 4
  132. #define BMA400_CMD_REG 0x7e
  133. /*
  134. * BMA400_SCALE_MIN macro value represents m/s^2 for 1 LSB before
  135. * converting to micro values for +-2g range.
  136. *
  137. * For +-2g - 1 LSB = 0.976562 milli g = 0.009576 m/s^2
  138. * For +-4g - 1 LSB = 1.953125 milli g = 0.019153 m/s^2
  139. * For +-16g - 1 LSB = 7.8125 milli g = 0.076614 m/s^2
  140. *
  141. * The raw value which is used to select the different ranges is determined
  142. * by the first bit set position from the scale value, so BMA400_SCALE_MIN
  143. * should be odd.
  144. *
  145. * Scale values for +-2g, +-4g, +-8g and +-16g are populated into bma400_scales
  146. * array by left shifting BMA400_SCALE_MIN.
  147. * e.g.:
  148. * To select +-2g = 9577 << 0 = raw value to write is 0.
  149. * To select +-8g = 9577 << 2 = raw value to write is 2.
  150. * To select +-16g = 9577 << 3 = raw value to write is 3.
  151. */
  152. #define BMA400_ACC_SCALE_MIN 9577
  153. #define BMA400_ACC_SCALE_MAX 76617
  154. extern const struct regmap_config bma400_regmap_config;
  155. int bma400_probe(struct device *dev, struct regmap *regmap, int irq,
  156. const char *name);
  157. #endif