bmp280-regmap.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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(bmp180_regmap_config);
  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. const struct regmap_config bmp280_regmap_config = {
  67. .reg_bits = 8,
  68. .val_bits = 8,
  69. .max_register = BMP280_REG_HUMIDITY_LSB,
  70. .cache_type = REGCACHE_RBTREE,
  71. .writeable_reg = bmp280_is_writeable_reg,
  72. .volatile_reg = bmp280_is_volatile_reg,
  73. };
  74. EXPORT_SYMBOL(bmp280_regmap_config);