bmp280.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #include <linux/bitops.h>
  3. #include <linux/device.h>
  4. #include <linux/regmap.h>
  5. /* BMP380 specific registers */
  6. #define BMP380_REG_CMD 0x7E
  7. #define BMP380_REG_CONFIG 0x1F
  8. #define BMP380_REG_ODR 0x1D
  9. #define BMP380_REG_OSR 0x1C
  10. #define BMP380_REG_POWER_CONTROL 0x1B
  11. #define BMP380_REG_IF_CONFIG 0x1A
  12. #define BMP380_REG_INT_CONTROL 0x19
  13. #define BMP380_REG_INT_STATUS 0x11
  14. #define BMP380_REG_EVENT 0x10
  15. #define BMP380_REG_STATUS 0x03
  16. #define BMP380_REG_ERROR 0x02
  17. #define BMP380_REG_ID 0x00
  18. #define BMP380_REG_FIFO_CONFIG_1 0x18
  19. #define BMP380_REG_FIFO_CONFIG_2 0x17
  20. #define BMP380_REG_FIFO_WATERMARK_MSB 0x16
  21. #define BMP380_REG_FIFO_WATERMARK_LSB 0x15
  22. #define BMP380_REG_FIFO_DATA 0x14
  23. #define BMP380_REG_FIFO_LENGTH_MSB 0x13
  24. #define BMP380_REG_FIFO_LENGTH_LSB 0x12
  25. #define BMP380_REG_SENSOR_TIME_MSB 0x0E
  26. #define BMP380_REG_SENSOR_TIME_LSB 0x0D
  27. #define BMP380_REG_SENSOR_TIME_XLSB 0x0C
  28. #define BMP380_REG_TEMP_MSB 0x09
  29. #define BMP380_REG_TEMP_LSB 0x08
  30. #define BMP380_REG_TEMP_XLSB 0x07
  31. #define BMP380_REG_PRESS_MSB 0x06
  32. #define BMP380_REG_PRESS_LSB 0x05
  33. #define BMP380_REG_PRESS_XLSB 0x04
  34. #define BMP380_REG_CALIB_TEMP_START 0x31
  35. #define BMP380_CALIB_REG_COUNT 21
  36. #define BMP380_FILTER_MASK GENMASK(3, 1)
  37. #define BMP380_FILTER_OFF 0
  38. #define BMP380_FILTER_1X 1
  39. #define BMP380_FILTER_3X 2
  40. #define BMP380_FILTER_7X 3
  41. #define BMP380_FILTER_15X 4
  42. #define BMP380_FILTER_31X 5
  43. #define BMP380_FILTER_63X 6
  44. #define BMP380_FILTER_127X 7
  45. #define BMP380_OSRS_TEMP_MASK GENMASK(5, 3)
  46. #define BMP380_OSRS_PRESS_MASK GENMASK(2, 0)
  47. #define BMP380_ODRS_MASK GENMASK(4, 0)
  48. #define BMP380_CTRL_SENSORS_MASK GENMASK(1, 0)
  49. #define BMP380_CTRL_SENSORS_PRESS_EN BIT(0)
  50. #define BMP380_CTRL_SENSORS_TEMP_EN BIT(1)
  51. #define BMP380_MODE_MASK GENMASK(5, 4)
  52. #define BMP380_MODE_SLEEP 0
  53. #define BMP380_MODE_FORCED 1
  54. #define BMP380_MODE_NORMAL 3
  55. #define BMP380_MIN_TEMP -4000
  56. #define BMP380_MAX_TEMP 8500
  57. #define BMP380_MIN_PRES 3000000
  58. #define BMP380_MAX_PRES 12500000
  59. #define BMP380_CMD_NOOP 0x00
  60. #define BMP380_CMD_EXTMODE_EN_MID 0x34
  61. #define BMP380_CMD_FIFO_FLUSH 0xB0
  62. #define BMP380_CMD_SOFT_RESET 0xB6
  63. #define BMP380_STATUS_CMD_RDY_MASK BIT(4)
  64. #define BMP380_STATUS_DRDY_PRESS_MASK BIT(5)
  65. #define BMP380_STATUS_DRDY_TEMP_MASK BIT(6)
  66. #define BMP380_ERR_FATAL_MASK BIT(0)
  67. #define BMP380_ERR_CMD_MASK BIT(1)
  68. #define BMP380_ERR_CONF_MASK BIT(2)
  69. #define BMP380_TEMP_SKIPPED 0x800000
  70. #define BMP380_PRESS_SKIPPED 0x800000
  71. /* BMP280 specific registers */
  72. #define BMP280_REG_HUMIDITY_LSB 0xFE
  73. #define BMP280_REG_HUMIDITY_MSB 0xFD
  74. #define BMP280_REG_TEMP_XLSB 0xFC
  75. #define BMP280_REG_TEMP_LSB 0xFB
  76. #define BMP280_REG_TEMP_MSB 0xFA
  77. #define BMP280_REG_PRESS_XLSB 0xF9
  78. #define BMP280_REG_PRESS_LSB 0xF8
  79. #define BMP280_REG_PRESS_MSB 0xF7
  80. /* Helper mask to truncate excess 4 bits on pressure and temp readings */
  81. #define BMP280_MEAS_TRIM_MASK GENMASK(24, 4)
  82. #define BMP280_REG_CONFIG 0xF5
  83. #define BMP280_REG_CTRL_MEAS 0xF4
  84. #define BMP280_REG_STATUS 0xF3
  85. #define BMP280_REG_CTRL_HUMIDITY 0xF2
  86. /* Due to non linear mapping, and data sizes we can't do a bulk read */
  87. #define BMP280_REG_COMP_H1 0xA1
  88. #define BMP280_REG_COMP_H2 0xE1
  89. #define BMP280_REG_COMP_H3 0xE3
  90. #define BMP280_REG_COMP_H4 0xE4
  91. #define BMP280_REG_COMP_H5 0xE5
  92. #define BMP280_REG_COMP_H6 0xE7
  93. #define BMP280_REG_COMP_TEMP_START 0x88
  94. #define BMP280_COMP_TEMP_REG_COUNT 6
  95. #define BMP280_REG_COMP_PRESS_START 0x8E
  96. #define BMP280_COMP_PRESS_REG_COUNT 18
  97. #define BMP280_COMP_H5_MASK GENMASK(15, 4)
  98. #define BMP280_CONTIGUOUS_CALIB_REGS (BMP280_COMP_TEMP_REG_COUNT + \
  99. BMP280_COMP_PRESS_REG_COUNT)
  100. #define BMP280_FILTER_MASK GENMASK(4, 2)
  101. #define BMP280_FILTER_OFF 0
  102. #define BMP280_FILTER_2X 1
  103. #define BMP280_FILTER_4X 2
  104. #define BMP280_FILTER_8X 3
  105. #define BMP280_FILTER_16X 4
  106. #define BMP280_OSRS_HUMIDITY_MASK GENMASK(2, 0)
  107. #define BMP280_OSRS_HUMIDITY_SKIP 0
  108. #define BMP280_OSRS_HUMIDITY_1X 1
  109. #define BMP280_OSRS_HUMIDITY_2X 2
  110. #define BMP280_OSRS_HUMIDITY_4X 3
  111. #define BMP280_OSRS_HUMIDITY_8X 4
  112. #define BMP280_OSRS_HUMIDITY_16X 5
  113. #define BMP280_OSRS_TEMP_MASK GENMASK(7, 5)
  114. #define BMP280_OSRS_TEMP_SKIP 0
  115. #define BMP280_OSRS_TEMP_1X 1
  116. #define BMP280_OSRS_TEMP_2X 2
  117. #define BMP280_OSRS_TEMP_4X 3
  118. #define BMP280_OSRS_TEMP_8X 4
  119. #define BMP280_OSRS_TEMP_16X 5
  120. #define BMP280_OSRS_PRESS_MASK GENMASK(4, 2)
  121. #define BMP280_OSRS_PRESS_SKIP 0
  122. #define BMP280_OSRS_PRESS_1X 1
  123. #define BMP280_OSRS_PRESS_2X 2
  124. #define BMP280_OSRS_PRESS_4X 3
  125. #define BMP280_OSRS_PRESS_8X 4
  126. #define BMP280_OSRS_PRESS_16X 5
  127. #define BMP280_MODE_MASK GENMASK(1, 0)
  128. #define BMP280_MODE_SLEEP 0
  129. #define BMP280_MODE_FORCED 1
  130. #define BMP280_MODE_NORMAL 3
  131. /* BMP180 specific registers */
  132. #define BMP180_REG_OUT_XLSB 0xF8
  133. #define BMP180_REG_OUT_LSB 0xF7
  134. #define BMP180_REG_OUT_MSB 0xF6
  135. #define BMP180_REG_CALIB_START 0xAA
  136. #define BMP180_REG_CALIB_COUNT 22
  137. #define BMP180_MEAS_CTRL_MASK GENMASK(4, 0)
  138. #define BMP180_MEAS_TEMP 0x0E
  139. #define BMP180_MEAS_PRESS 0x14
  140. #define BMP180_MEAS_SCO BIT(5)
  141. #define BMP180_OSRS_PRESS_MASK GENMASK(7, 6)
  142. #define BMP180_MEAS_PRESS_1X 0
  143. #define BMP180_MEAS_PRESS_2X 1
  144. #define BMP180_MEAS_PRESS_4X 2
  145. #define BMP180_MEAS_PRESS_8X 3
  146. /* BMP180 and BMP280 common registers */
  147. #define BMP280_REG_CTRL_MEAS 0xF4
  148. #define BMP280_REG_RESET 0xE0
  149. #define BMP280_REG_ID 0xD0
  150. #define BMP380_CHIP_ID 0x50
  151. #define BMP180_CHIP_ID 0x55
  152. #define BMP280_CHIP_ID 0x58
  153. #define BME280_CHIP_ID 0x60
  154. #define BMP280_SOFT_RESET_VAL 0xB6
  155. /* BMP280 register skipped special values */
  156. #define BMP280_TEMP_SKIPPED 0x80000
  157. #define BMP280_PRESS_SKIPPED 0x80000
  158. #define BMP280_HUMIDITY_SKIPPED 0x8000
  159. /* Regmap configurations */
  160. extern const struct regmap_config bmp180_regmap_config;
  161. extern const struct regmap_config bmp280_regmap_config;
  162. extern const struct regmap_config bmp380_regmap_config;
  163. /* Probe called from different transports */
  164. int bmp280_common_probe(struct device *dev,
  165. struct regmap *regmap,
  166. unsigned int chip,
  167. const char *name,
  168. int irq);
  169. /* PM ops */
  170. extern const struct dev_pm_ops bmp280_dev_pm_ops;