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