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 bme280_is_writeable_reg(struct device *dev, unsigned int reg) 45 { 46 switch (reg) { 47 case BMP280_REG_CONFIG: 48 case BME280_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_writeable_reg(struct device *dev, unsigned int reg) 58 { 59 switch (reg) { 60 case BMP280_REG_CONFIG: 61 case BMP280_REG_CTRL_MEAS: 62 case BMP280_REG_RESET: 63 return true; 64 default: 65 return false; 66 } 67 } 68 69 static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg) 70 { 71 switch (reg) { 72 case BMP280_REG_TEMP_XLSB: 73 case BMP280_REG_TEMP_LSB: 74 case BMP280_REG_TEMP_MSB: 75 case BMP280_REG_PRESS_XLSB: 76 case BMP280_REG_PRESS_LSB: 77 case BMP280_REG_PRESS_MSB: 78 case BMP280_REG_STATUS: 79 return true; 80 default: 81 return false; 82 } 83 } 84 85 static bool bme280_is_volatile_reg(struct device *dev, unsigned int reg) 86 { 87 switch (reg) { 88 case BME280_REG_HUMIDITY_LSB: 89 case BME280_REG_HUMIDITY_MSB: 90 case BMP280_REG_TEMP_XLSB: 91 case BMP280_REG_TEMP_LSB: 92 case BMP280_REG_TEMP_MSB: 93 case BMP280_REG_PRESS_XLSB: 94 case BMP280_REG_PRESS_LSB: 95 case BMP280_REG_PRESS_MSB: 96 case BMP280_REG_STATUS: 97 return true; 98 default: 99 return false; 100 } 101 } 102 static bool bmp380_is_writeable_reg(struct device *dev, unsigned int reg) 103 { 104 switch (reg) { 105 case BMP380_REG_CMD: 106 case BMP380_REG_CONFIG: 107 case BMP380_REG_FIFO_CONFIG_1: 108 case BMP380_REG_FIFO_CONFIG_2: 109 case BMP380_REG_FIFO_WATERMARK_LSB: 110 case BMP380_REG_FIFO_WATERMARK_MSB: 111 case BMP380_REG_POWER_CONTROL: 112 case BMP380_REG_INT_CONTROL: 113 case BMP380_REG_IF_CONFIG: 114 case BMP380_REG_ODR: 115 case BMP380_REG_OSR: 116 return true; 117 default: 118 return false; 119 } 120 } 121 122 static bool bmp380_is_volatile_reg(struct device *dev, unsigned int reg) 123 { 124 switch (reg) { 125 case BMP380_REG_TEMP_XLSB: 126 case BMP380_REG_TEMP_LSB: 127 case BMP380_REG_TEMP_MSB: 128 case BMP380_REG_PRESS_XLSB: 129 case BMP380_REG_PRESS_LSB: 130 case BMP380_REG_PRESS_MSB: 131 case BMP380_REG_SENSOR_TIME_XLSB: 132 case BMP380_REG_SENSOR_TIME_LSB: 133 case BMP380_REG_SENSOR_TIME_MSB: 134 case BMP380_REG_INT_STATUS: 135 case BMP380_REG_FIFO_DATA: 136 case BMP380_REG_STATUS: 137 case BMP380_REG_ERROR: 138 case BMP380_REG_EVENT: 139 return true; 140 default: 141 return false; 142 } 143 } 144 145 static bool bmp580_is_writeable_reg(struct device *dev, unsigned int reg) 146 { 147 switch (reg) { 148 case BMP580_REG_NVM_DATA_MSB: 149 case BMP580_REG_NVM_DATA_LSB: 150 case BMP580_REG_NVM_ADDR: 151 case BMP580_REG_ODR_CONFIG: 152 case BMP580_REG_OSR_CONFIG: 153 case BMP580_REG_INT_SOURCE: 154 case BMP580_REG_INT_CONFIG: 155 case BMP580_REG_OOR_THR_MSB: 156 case BMP580_REG_OOR_THR_LSB: 157 case BMP580_REG_OOR_CONFIG: 158 case BMP580_REG_OOR_RANGE: 159 case BMP580_REG_IF_CONFIG: 160 case BMP580_REG_FIFO_CONFIG: 161 case BMP580_REG_FIFO_SEL: 162 case BMP580_REG_DSP_CONFIG: 163 case BMP580_REG_DSP_IIR: 164 case BMP580_REG_CMD: 165 return true; 166 default: 167 return false; 168 } 169 } 170 171 static bool bmp580_is_volatile_reg(struct device *dev, unsigned int reg) 172 { 173 switch (reg) { 174 case BMP580_REG_NVM_DATA_MSB: 175 case BMP580_REG_NVM_DATA_LSB: 176 case BMP580_REG_FIFO_COUNT: 177 case BMP580_REG_INT_STATUS: 178 case BMP580_REG_PRESS_XLSB: 179 case BMP580_REG_PRESS_LSB: 180 case BMP580_REG_PRESS_MSB: 181 case BMP580_REG_FIFO_DATA: 182 case BMP580_REG_TEMP_XLSB: 183 case BMP580_REG_TEMP_LSB: 184 case BMP580_REG_TEMP_MSB: 185 case BMP580_REG_EFF_OSR: 186 case BMP580_REG_STATUS: 187 return true; 188 default: 189 return false; 190 } 191 } 192 193 const struct regmap_config bmp280_regmap_config = { 194 .reg_bits = 8, 195 .val_bits = 8, 196 197 .max_register = BMP280_REG_TEMP_XLSB, 198 .cache_type = REGCACHE_RBTREE, 199 200 .writeable_reg = bmp280_is_writeable_reg, 201 .volatile_reg = bmp280_is_volatile_reg, 202 }; 203 EXPORT_SYMBOL_NS(bmp280_regmap_config, IIO_BMP280); 204 205 const struct regmap_config bme280_regmap_config = { 206 .reg_bits = 8, 207 .val_bits = 8, 208 209 .max_register = BME280_REG_HUMIDITY_LSB, 210 .cache_type = REGCACHE_RBTREE, 211 212 .writeable_reg = bme280_is_writeable_reg, 213 .volatile_reg = bme280_is_volatile_reg, 214 }; 215 EXPORT_SYMBOL_NS(bme280_regmap_config, IIO_BMP280); 216 217 const struct regmap_config bmp380_regmap_config = { 218 .reg_bits = 8, 219 .val_bits = 8, 220 221 .max_register = BMP380_REG_CMD, 222 .cache_type = REGCACHE_RBTREE, 223 224 .writeable_reg = bmp380_is_writeable_reg, 225 .volatile_reg = bmp380_is_volatile_reg, 226 }; 227 EXPORT_SYMBOL_NS(bmp380_regmap_config, IIO_BMP280); 228 229 const struct regmap_config bmp580_regmap_config = { 230 .reg_bits = 8, 231 .val_bits = 8, 232 233 .max_register = BMP580_REG_CMD, 234 .cache_type = REGCACHE_RBTREE, 235 236 .writeable_reg = bmp580_is_writeable_reg, 237 .volatile_reg = bmp580_is_volatile_reg, 238 }; 239 EXPORT_SYMBOL_NS(bmp580_regmap_config, IIO_BMP280); 240