bmp280-regmap.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/device.h>
  3. #include <linux/module.h>
  4. #include <linux/regmap.h>
  5. #include "bmp280.h"
  6. static bool bmp180_is_writeable_reg(struct device *dev, unsigned int reg)
  7. {
  8. switch (reg) {
  9. case BMP280_REG_CTRL_MEAS:
  10. case BMP280_REG_RESET:
  11. return true;
  12. default:
  13. return false;
  14. }
  15. }
  16. static bool bmp180_is_volatile_reg(struct device *dev, unsigned int reg)
  17. {
  18. switch (reg) {
  19. case BMP180_REG_OUT_XLSB:
  20. case BMP180_REG_OUT_LSB:
  21. case BMP180_REG_OUT_MSB:
  22. case BMP280_REG_CTRL_MEAS:
  23. return true;
  24. default:
  25. return false;
  26. }
  27. }
  28. const struct regmap_config bmp180_regmap_config = {
  29. .reg_bits = 8,
  30. .val_bits = 8,
  31. .max_register = BMP180_REG_OUT_XLSB,
  32. .cache_type = REGCACHE_RBTREE,
  33. .writeable_reg = bmp180_is_writeable_reg,
  34. .volatile_reg = bmp180_is_volatile_reg,
  35. };
  36. EXPORT_SYMBOL_NS(bmp180_regmap_config, IIO_BMP280);
  37. static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg)
  38. {
  39. switch (reg) {
  40. case BMP280_REG_CONFIG:
  41. case BMP280_REG_CTRL_HUMIDITY:
  42. case BMP280_REG_CTRL_MEAS:
  43. case BMP280_REG_RESET:
  44. return true;
  45. default:
  46. return false;
  47. }
  48. }
  49. static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg)
  50. {
  51. switch (reg) {
  52. case BMP280_REG_HUMIDITY_LSB:
  53. case BMP280_REG_HUMIDITY_MSB:
  54. case BMP280_REG_TEMP_XLSB:
  55. case BMP280_REG_TEMP_LSB:
  56. case BMP280_REG_TEMP_MSB:
  57. case BMP280_REG_PRESS_XLSB:
  58. case BMP280_REG_PRESS_LSB:
  59. case BMP280_REG_PRESS_MSB:
  60. case BMP280_REG_STATUS:
  61. return true;
  62. default:
  63. return false;
  64. }
  65. }
  66. static bool bmp380_is_writeable_reg(struct device *dev, unsigned int reg)
  67. {
  68. switch (reg) {
  69. case BMP380_REG_CMD:
  70. case BMP380_REG_CONFIG:
  71. case BMP380_REG_FIFO_CONFIG_1:
  72. case BMP380_REG_FIFO_CONFIG_2:
  73. case BMP380_REG_FIFO_WATERMARK_LSB:
  74. case BMP380_REG_FIFO_WATERMARK_MSB:
  75. case BMP380_REG_POWER_CONTROL:
  76. case BMP380_REG_INT_CONTROL:
  77. case BMP380_REG_IF_CONFIG:
  78. case BMP380_REG_ODR:
  79. case BMP380_REG_OSR:
  80. return true;
  81. default:
  82. return false;
  83. }
  84. }
  85. static bool bmp380_is_volatile_reg(struct device *dev, unsigned int reg)
  86. {
  87. switch (reg) {
  88. case BMP380_REG_TEMP_XLSB:
  89. case BMP380_REG_TEMP_LSB:
  90. case BMP380_REG_TEMP_MSB:
  91. case BMP380_REG_PRESS_XLSB:
  92. case BMP380_REG_PRESS_LSB:
  93. case BMP380_REG_PRESS_MSB:
  94. case BMP380_REG_SENSOR_TIME_XLSB:
  95. case BMP380_REG_SENSOR_TIME_LSB:
  96. case BMP380_REG_SENSOR_TIME_MSB:
  97. case BMP380_REG_INT_STATUS:
  98. case BMP380_REG_FIFO_DATA:
  99. case BMP380_REG_STATUS:
  100. case BMP380_REG_ERROR:
  101. case BMP380_REG_EVENT:
  102. return true;
  103. default:
  104. return false;
  105. }
  106. }
  107. const struct regmap_config bmp280_regmap_config = {
  108. .reg_bits = 8,
  109. .val_bits = 8,
  110. .max_register = BMP280_REG_HUMIDITY_LSB,
  111. .cache_type = REGCACHE_RBTREE,
  112. .writeable_reg = bmp280_is_writeable_reg,
  113. .volatile_reg = bmp280_is_volatile_reg,
  114. };
  115. EXPORT_SYMBOL_NS(bmp280_regmap_config, IIO_BMP280);
  116. const struct regmap_config bmp380_regmap_config = {
  117. .reg_bits = 8,
  118. .val_bits = 8,
  119. .max_register = BMP380_REG_CMD,
  120. .cache_type = REGCACHE_RBTREE,
  121. .writeable_reg = bmp380_is_writeable_reg,
  122. .volatile_reg = bmp380_is_volatile_reg,
  123. };
  124. EXPORT_SYMBOL_NS(bmp380_regmap_config, IIO_BMP280);