bmp280-regmap.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <linux/device.h>
  2. #include <linux/module.h>
  3. #include <linux/regmap.h>
  4. #include "bmp280.h"
  5. static bool bmp180_is_writeable_reg(struct device *dev, unsigned int reg)
  6. {
  7. switch (reg) {
  8. case BMP280_REG_CTRL_MEAS:
  9. case BMP280_REG_RESET:
  10. return true;
  11. default:
  12. return false;
  13. };
  14. }
  15. static bool bmp180_is_volatile_reg(struct device *dev, unsigned int reg)
  16. {
  17. switch (reg) {
  18. case BMP180_REG_OUT_XLSB:
  19. case BMP180_REG_OUT_LSB:
  20. case BMP180_REG_OUT_MSB:
  21. case BMP280_REG_CTRL_MEAS:
  22. return true;
  23. default:
  24. return false;
  25. }
  26. }
  27. const struct regmap_config bmp180_regmap_config = {
  28. .reg_bits = 8,
  29. .val_bits = 8,
  30. .max_register = BMP180_REG_OUT_XLSB,
  31. .cache_type = REGCACHE_RBTREE,
  32. .writeable_reg = bmp180_is_writeable_reg,
  33. .volatile_reg = bmp180_is_volatile_reg,
  34. };
  35. EXPORT_SYMBOL(bmp180_regmap_config);
  36. static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg)
  37. {
  38. switch (reg) {
  39. case BMP280_REG_CONFIG:
  40. case BMP280_REG_CTRL_HUMIDITY:
  41. case BMP280_REG_CTRL_MEAS:
  42. case BMP280_REG_RESET:
  43. return true;
  44. default:
  45. return false;
  46. };
  47. }
  48. static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg)
  49. {
  50. switch (reg) {
  51. case BMP280_REG_HUMIDITY_LSB:
  52. case BMP280_REG_HUMIDITY_MSB:
  53. case BMP280_REG_TEMP_XLSB:
  54. case BMP280_REG_TEMP_LSB:
  55. case BMP280_REG_TEMP_MSB:
  56. case BMP280_REG_PRESS_XLSB:
  57. case BMP280_REG_PRESS_LSB:
  58. case BMP280_REG_PRESS_MSB:
  59. case BMP280_REG_STATUS:
  60. return true;
  61. default:
  62. return false;
  63. }
  64. }
  65. const struct regmap_config bmp280_regmap_config = {
  66. .reg_bits = 8,
  67. .val_bits = 8,
  68. .max_register = BMP280_REG_HUMIDITY_LSB,
  69. .cache_type = REGCACHE_RBTREE,
  70. .writeable_reg = bmp280_is_writeable_reg,
  71. .volatile_reg = bmp280_is_volatile_reg,
  72. };
  73. EXPORT_SYMBOL(bmp280_regmap_config);