18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci#include <linux/device.h> 38c2ecf20Sopenharmony_ci#include <linux/module.h> 48c2ecf20Sopenharmony_ci#include <linux/regmap.h> 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include "bmp280.h" 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_cistatic bool bmp180_is_writeable_reg(struct device *dev, unsigned int reg) 98c2ecf20Sopenharmony_ci{ 108c2ecf20Sopenharmony_ci switch (reg) { 118c2ecf20Sopenharmony_ci case BMP280_REG_CTRL_MEAS: 128c2ecf20Sopenharmony_ci case BMP280_REG_RESET: 138c2ecf20Sopenharmony_ci return true; 148c2ecf20Sopenharmony_ci default: 158c2ecf20Sopenharmony_ci return false; 168c2ecf20Sopenharmony_ci }; 178c2ecf20Sopenharmony_ci} 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistatic bool bmp180_is_volatile_reg(struct device *dev, unsigned int reg) 208c2ecf20Sopenharmony_ci{ 218c2ecf20Sopenharmony_ci switch (reg) { 228c2ecf20Sopenharmony_ci case BMP180_REG_OUT_XLSB: 238c2ecf20Sopenharmony_ci case BMP180_REG_OUT_LSB: 248c2ecf20Sopenharmony_ci case BMP180_REG_OUT_MSB: 258c2ecf20Sopenharmony_ci case BMP280_REG_CTRL_MEAS: 268c2ecf20Sopenharmony_ci return true; 278c2ecf20Sopenharmony_ci default: 288c2ecf20Sopenharmony_ci return false; 298c2ecf20Sopenharmony_ci } 308c2ecf20Sopenharmony_ci} 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ciconst struct regmap_config bmp180_regmap_config = { 338c2ecf20Sopenharmony_ci .reg_bits = 8, 348c2ecf20Sopenharmony_ci .val_bits = 8, 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci .max_register = BMP180_REG_OUT_XLSB, 378c2ecf20Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci .writeable_reg = bmp180_is_writeable_reg, 408c2ecf20Sopenharmony_ci .volatile_reg = bmp180_is_volatile_reg, 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ciEXPORT_SYMBOL(bmp180_regmap_config); 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg) 458c2ecf20Sopenharmony_ci{ 468c2ecf20Sopenharmony_ci switch (reg) { 478c2ecf20Sopenharmony_ci case BMP280_REG_CONFIG: 488c2ecf20Sopenharmony_ci case BMP280_REG_CTRL_HUMIDITY: 498c2ecf20Sopenharmony_ci case BMP280_REG_CTRL_MEAS: 508c2ecf20Sopenharmony_ci case BMP280_REG_RESET: 518c2ecf20Sopenharmony_ci return true; 528c2ecf20Sopenharmony_ci default: 538c2ecf20Sopenharmony_ci return false; 548c2ecf20Sopenharmony_ci }; 558c2ecf20Sopenharmony_ci} 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cistatic bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci switch (reg) { 608c2ecf20Sopenharmony_ci case BMP280_REG_HUMIDITY_LSB: 618c2ecf20Sopenharmony_ci case BMP280_REG_HUMIDITY_MSB: 628c2ecf20Sopenharmony_ci case BMP280_REG_TEMP_XLSB: 638c2ecf20Sopenharmony_ci case BMP280_REG_TEMP_LSB: 648c2ecf20Sopenharmony_ci case BMP280_REG_TEMP_MSB: 658c2ecf20Sopenharmony_ci case BMP280_REG_PRESS_XLSB: 668c2ecf20Sopenharmony_ci case BMP280_REG_PRESS_LSB: 678c2ecf20Sopenharmony_ci case BMP280_REG_PRESS_MSB: 688c2ecf20Sopenharmony_ci case BMP280_REG_STATUS: 698c2ecf20Sopenharmony_ci return true; 708c2ecf20Sopenharmony_ci default: 718c2ecf20Sopenharmony_ci return false; 728c2ecf20Sopenharmony_ci } 738c2ecf20Sopenharmony_ci} 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ciconst struct regmap_config bmp280_regmap_config = { 768c2ecf20Sopenharmony_ci .reg_bits = 8, 778c2ecf20Sopenharmony_ci .val_bits = 8, 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci .max_register = BMP280_REG_HUMIDITY_LSB, 808c2ecf20Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci .writeable_reg = bmp280_is_writeable_reg, 838c2ecf20Sopenharmony_ci .volatile_reg = bmp280_is_volatile_reg, 848c2ecf20Sopenharmony_ci}; 858c2ecf20Sopenharmony_ciEXPORT_SYMBOL(bmp280_regmap_config); 86