Commit 597dfb2a authored by Angel Iglesias's avatar Angel Iglesias Committed by Jonathan Cameron

iio: pressure: bmp280: Add support for new sensor BMP580

Adds compatibility with the new sensor generation, the BMP580.

The measurement and initialization codepaths are adapted from
the device datasheet and the repository from manufacturer at
https://github.com/boschsensortec/BMP5-Sensor-API.
Signed-off-by: default avatarAngel Iglesias <ang.iglesiasg@gmail.com>
Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/f899fceec9b48bc173bd4b7555f0a237fa32d520.1676823250.git.ang.iglesiasg@gmail.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 42cde880
...@@ -17,14 +17,14 @@ config ABP060MG ...@@ -17,14 +17,14 @@ config ABP060MG
will be called abp060mg. will be called abp060mg.
config BMP280 config BMP280
tristate "Bosch Sensortec BMP180/BMP280/BMP380 pressure sensor driver" tristate "Bosch Sensortec BMP180/BMP280/BMP380/BMP580 pressure sensor driver"
depends on (I2C || SPI_MASTER) depends on (I2C || SPI_MASTER)
select REGMAP select REGMAP
select BMP280_I2C if (I2C) select BMP280_I2C if (I2C)
select BMP280_SPI if (SPI_MASTER) select BMP280_SPI if (SPI_MASTER)
help help
Say yes here to build support for Bosch Sensortec BMP180, BMP280 and Say yes here to build support for Bosch Sensortec BMP180, BMP280, BMP380
BMP380 pressure and temperature sensors. Also supports the BME280 with and BMP580 pressure and temperature sensors. Also supports the BME280 with
an additional humidity sensor channel. an additional humidity sensor channel.
To compile this driver as a module, choose M here: the core module To compile this driver as a module, choose M here: the core module
......
This diff is collapsed.
...@@ -34,6 +34,7 @@ static const struct of_device_id bmp280_of_i2c_match[] = { ...@@ -34,6 +34,7 @@ static const struct of_device_id bmp280_of_i2c_match[] = {
{ .compatible = "bosch,bmp280", .data = &bmp280_chip_info }, { .compatible = "bosch,bmp280", .data = &bmp280_chip_info },
{ .compatible = "bosch,bme280", .data = &bme280_chip_info }, { .compatible = "bosch,bme280", .data = &bme280_chip_info },
{ .compatible = "bosch,bmp380", .data = &bmp380_chip_info }, { .compatible = "bosch,bmp380", .data = &bmp380_chip_info },
{ .compatible = "bosch,bmp580", .data = &bmp580_chip_info },
{ }, { },
}; };
MODULE_DEVICE_TABLE(of, bmp280_of_i2c_match); MODULE_DEVICE_TABLE(of, bmp280_of_i2c_match);
...@@ -44,6 +45,7 @@ static const struct i2c_device_id bmp280_i2c_id[] = { ...@@ -44,6 +45,7 @@ static const struct i2c_device_id bmp280_i2c_id[] = {
{"bmp280", (kernel_ulong_t)&bmp280_chip_info }, {"bmp280", (kernel_ulong_t)&bmp280_chip_info },
{"bme280", (kernel_ulong_t)&bme280_chip_info }, {"bme280", (kernel_ulong_t)&bme280_chip_info },
{"bmp380", (kernel_ulong_t)&bmp380_chip_info }, {"bmp380", (kernel_ulong_t)&bmp380_chip_info },
{"bmp580", (kernel_ulong_t)&bmp580_chip_info },
{ }, { },
}; };
MODULE_DEVICE_TABLE(i2c, bmp280_i2c_id); MODULE_DEVICE_TABLE(i2c, bmp280_i2c_id);
......
...@@ -115,6 +115,54 @@ static bool bmp380_is_volatile_reg(struct device *dev, unsigned int reg) ...@@ -115,6 +115,54 @@ static bool bmp380_is_volatile_reg(struct device *dev, unsigned int reg)
} }
} }
static bool bmp580_is_writeable_reg(struct device *dev, unsigned int reg)
{
switch (reg) {
case BMP580_REG_NVM_DATA_MSB:
case BMP580_REG_NVM_DATA_LSB:
case BMP580_REG_NVM_ADDR:
case BMP580_REG_ODR_CONFIG:
case BMP580_REG_OSR_CONFIG:
case BMP580_REG_INT_SOURCE:
case BMP580_REG_INT_CONFIG:
case BMP580_REG_OOR_THR_MSB:
case BMP580_REG_OOR_THR_LSB:
case BMP580_REG_OOR_CONFIG:
case BMP580_REG_OOR_RANGE:
case BMP580_REG_IF_CONFIG:
case BMP580_REG_FIFO_CONFIG:
case BMP580_REG_FIFO_SEL:
case BMP580_REG_DSP_CONFIG:
case BMP580_REG_DSP_IIR:
case BMP580_REG_CMD:
return true;
default:
return false;
}
}
static bool bmp580_is_volatile_reg(struct device *dev, unsigned int reg)
{
switch (reg) {
case BMP580_REG_NVM_DATA_MSB:
case BMP580_REG_NVM_DATA_LSB:
case BMP580_REG_FIFO_COUNT:
case BMP580_REG_INT_STATUS:
case BMP580_REG_PRESS_XLSB:
case BMP580_REG_PRESS_LSB:
case BMP580_REG_PRESS_MSB:
case BMP580_REG_FIFO_DATA:
case BMP580_REG_TEMP_XLSB:
case BMP580_REG_TEMP_LSB:
case BMP580_REG_TEMP_MSB:
case BMP580_REG_EFF_OSR:
case BMP580_REG_STATUS:
return true;
default:
return false;
}
}
const struct regmap_config bmp280_regmap_config = { const struct regmap_config bmp280_regmap_config = {
.reg_bits = 8, .reg_bits = 8,
.val_bits = 8, .val_bits = 8,
...@@ -138,3 +186,15 @@ const struct regmap_config bmp380_regmap_config = { ...@@ -138,3 +186,15 @@ const struct regmap_config bmp380_regmap_config = {
.volatile_reg = bmp380_is_volatile_reg, .volatile_reg = bmp380_is_volatile_reg,
}; };
EXPORT_SYMBOL_NS(bmp380_regmap_config, IIO_BMP280); EXPORT_SYMBOL_NS(bmp380_regmap_config, IIO_BMP280);
const struct regmap_config bmp580_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = BMP580_REG_CMD,
.cache_type = REGCACHE_RBTREE,
.writeable_reg = bmp580_is_writeable_reg,
.volatile_reg = bmp580_is_volatile_reg,
};
EXPORT_SYMBOL_NS(bmp580_regmap_config, IIO_BMP280);
...@@ -85,6 +85,7 @@ static const struct of_device_id bmp280_of_spi_match[] = { ...@@ -85,6 +85,7 @@ static const struct of_device_id bmp280_of_spi_match[] = {
{ .compatible = "bosch,bmp280", .data = &bmp280_chip_info }, { .compatible = "bosch,bmp280", .data = &bmp280_chip_info },
{ .compatible = "bosch,bme280", .data = &bmp280_chip_info }, { .compatible = "bosch,bme280", .data = &bmp280_chip_info },
{ .compatible = "bosch,bmp380", .data = &bmp380_chip_info }, { .compatible = "bosch,bmp380", .data = &bmp380_chip_info },
{ .compatible = "bosch,bmp580", .data = &bmp580_chip_info },
{ }, { },
}; };
MODULE_DEVICE_TABLE(of, bmp280_of_spi_match); MODULE_DEVICE_TABLE(of, bmp280_of_spi_match);
...@@ -95,6 +96,7 @@ static const struct spi_device_id bmp280_spi_id[] = { ...@@ -95,6 +96,7 @@ static const struct spi_device_id bmp280_spi_id[] = {
{ "bmp280", (kernel_ulong_t)&bmp280_chip_info }, { "bmp280", (kernel_ulong_t)&bmp280_chip_info },
{ "bme280", (kernel_ulong_t)&bmp280_chip_info }, { "bme280", (kernel_ulong_t)&bmp280_chip_info },
{ "bmp380", (kernel_ulong_t)&bmp380_chip_info }, { "bmp380", (kernel_ulong_t)&bmp380_chip_info },
{ "bmp580", (kernel_ulong_t)&bmp580_chip_info },
{ } { }
}; };
MODULE_DEVICE_TABLE(spi, bmp280_spi_id); MODULE_DEVICE_TABLE(spi, bmp280_spi_id);
......
...@@ -6,6 +6,107 @@ ...@@ -6,6 +6,107 @@
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
/* BMP580 specific registers */
#define BMP580_REG_CMD 0x7E
#define BMP580_REG_EFF_OSR 0x38
#define BMP580_REG_ODR_CONFIG 0x37
#define BMP580_REG_OSR_CONFIG 0x36
#define BMP580_REG_IF_CONFIG 0x13
#define BMP580_REG_REV_ID 0x02
#define BMP580_REG_CHIP_ID 0x01
/* OOR allows to configure a pressure alarm */
#define BMP580_REG_OOR_CONFIG 0x35
#define BMP580_REG_OOR_RANGE 0x34
#define BMP580_REG_OOR_THR_MSB 0x33
#define BMP580_REG_OOR_THR_LSB 0x32
/* DSP registers (IIR filters) */
#define BMP580_REG_DSP_IIR 0x31
#define BMP580_REG_DSP_CONFIG 0x30
/* NVM access registers */
#define BMP580_REG_NVM_DATA_MSB 0x2D
#define BMP580_REG_NVM_DATA_LSB 0x2C
#define BMP580_REG_NVM_ADDR 0x2B
/* Status registers */
#define BMP580_REG_STATUS 0x28
#define BMP580_REG_INT_STATUS 0x27
#define BMP580_REG_CHIP_STATUS 0x11
/* Data registers */
#define BMP580_REG_FIFO_DATA 0x29
#define BMP580_REG_PRESS_MSB 0x22
#define BMP580_REG_PRESS_LSB 0x21
#define BMP580_REG_PRESS_XLSB 0x20
#define BMP580_REG_TEMP_MSB 0x1F
#define BMP580_REG_TEMP_LSB 0x1E
#define BMP580_REG_TEMP_XLSB 0x1D
/* FIFO config registers */
#define BMP580_REG_FIFO_SEL 0x18
#define BMP580_REG_FIFO_COUNT 0x17
#define BMP580_REG_FIFO_CONFIG 0x16
/* Interruptions config registers */
#define BMP580_REG_INT_SOURCE 0x15
#define BMP580_REG_INT_CONFIG 0x14
#define BMP580_CMD_NOOP 0x00
#define BMP580_CMD_EXTMODE_SEQ_0 0x73
#define BMP580_CMD_EXTMODE_SEQ_1 0xB4
#define BMP580_CMD_EXTMODE_SEQ_2 0x69
#define BMP580_CMD_NVM_OP_SEQ_0 0x5D
#define BMP580_CMD_NVM_READ_SEQ_1 0xA5
#define BMP580_CMD_NVM_WRITE_SEQ_1 0xA0
#define BMP580_CMD_SOFT_RESET 0xB6
#define BMP580_INT_STATUS_POR_MASK BIT(4)
#define BMP580_STATUS_CORE_RDY_MASK BIT(0)
#define BMP580_STATUS_NVM_RDY_MASK BIT(1)
#define BMP580_STATUS_NVM_ERR_MASK BIT(2)
#define BMP580_STATUS_NVM_CMD_ERR_MASK BIT(3)
#define BMP580_OSR_PRESS_MASK GENMASK(5, 3)
#define BMP580_OSR_TEMP_MASK GENMASK(2, 0)
#define BMP580_OSR_PRESS_EN BIT(6)
#define BMP580_EFF_OSR_PRESS_MASK GENMASK(5, 3)
#define BMP580_EFF_OSR_TEMP_MASK GENMASK(2, 0)
#define BMP580_EFF_OSR_VALID_ODR BIT(7)
#define BMP580_ODR_MASK GENMASK(6, 2)
#define BMP580_MODE_MASK GENMASK(1, 0)
#define BMP580_MODE_SLEEP 0
#define BMP580_MODE_NORMAL 1
#define BMP580_MODE_FORCED 2
#define BMP580_MODE_CONTINOUS 3
#define BMP580_ODR_DEEPSLEEP_DIS BIT(7)
#define BMP580_DSP_COMP_MASK GENMASK(1, 0)
#define BMP580_DSP_COMP_DIS 0
#define BMP580_DSP_TEMP_COMP_EN 1
/*
* In section 7.27 of datasheet, modes 2 and 3 are technically the same.
* Pressure compensation means also enabling temperature compensation
*/
#define BMP580_DSP_PRESS_COMP_EN 2
#define BMP580_DSP_PRESS_TEMP_COMP_EN 3
#define BMP580_DSP_IIR_FORCED_FLUSH BIT(2)
#define BMP580_DSP_SHDW_IIR_TEMP_EN BIT(3)
#define BMP580_DSP_FIFO_IIR_TEMP_EN BIT(4)
#define BMP580_DSP_SHDW_IIR_PRESS_EN BIT(5)
#define BMP580_DSP_FIFO_IIR_PRESS_EN BIT(6)
#define BMP580_DSP_OOR_IIR_PRESS_EN BIT(7)
#define BMP580_DSP_IIR_PRESS_MASK GENMASK(5, 3)
#define BMP580_DSP_IIR_TEMP_MASK GENMASK(2, 0)
#define BMP580_FILTER_OFF 0
#define BMP580_FILTER_1X 1
#define BMP580_FILTER_3X 2
#define BMP580_FILTER_7X 3
#define BMP580_FILTER_15X 4
#define BMP580_FILTER_31X 5
#define BMP580_FILTER_63X 6
#define BMP580_FILTER_127X 7
#define BMP580_TEMP_SKIPPED 0x7f7f7f
#define BMP580_PRESS_SKIPPED 0x7f7f7f
/* BMP380 specific registers */ /* BMP380 specific registers */
#define BMP380_REG_CMD 0x7E #define BMP380_REG_CMD 0x7E
#define BMP380_REG_CONFIG 0x1F #define BMP380_REG_CONFIG 0x1F
...@@ -184,6 +285,8 @@ ...@@ -184,6 +285,8 @@
#define BMP280_REG_ID 0xD0 #define BMP280_REG_ID 0xD0
#define BMP380_CHIP_ID 0x50 #define BMP380_CHIP_ID 0x50
#define BMP580_CHIP_ID 0x50
#define BMP580_CHIP_ID_ALT 0x51
#define BMP180_CHIP_ID 0x55 #define BMP180_CHIP_ID 0x55
#define BMP280_CHIP_ID 0x58 #define BMP280_CHIP_ID 0x58
#define BME280_CHIP_ID 0x60 #define BME280_CHIP_ID 0x60
...@@ -341,7 +444,7 @@ struct bmp280_chip_info { ...@@ -341,7 +444,7 @@ struct bmp280_chip_info {
int sampling_freq_default; int sampling_freq_default;
int (*chip_config)(struct bmp280_data *); int (*chip_config)(struct bmp280_data *);
int (*read_temp)(struct bmp280_data *, int *); int (*read_temp)(struct bmp280_data *, int *, int *);
int (*read_press)(struct bmp280_data *, int *, int *); int (*read_press)(struct bmp280_data *, int *, int *);
int (*read_humid)(struct bmp280_data *, int *, int *); int (*read_humid)(struct bmp280_data *, int *, int *);
int (*read_calib)(struct bmp280_data *); int (*read_calib)(struct bmp280_data *);
...@@ -353,11 +456,13 @@ extern const struct bmp280_chip_info bmp180_chip_info; ...@@ -353,11 +456,13 @@ extern const struct bmp280_chip_info bmp180_chip_info;
extern const struct bmp280_chip_info bmp280_chip_info; extern const struct bmp280_chip_info bmp280_chip_info;
extern const struct bmp280_chip_info bme280_chip_info; extern const struct bmp280_chip_info bme280_chip_info;
extern const struct bmp280_chip_info bmp380_chip_info; extern const struct bmp280_chip_info bmp380_chip_info;
extern const struct bmp280_chip_info bmp580_chip_info;
/* Regmap configurations */ /* Regmap configurations */
extern const struct regmap_config bmp180_regmap_config; extern const struct regmap_config bmp180_regmap_config;
extern const struct regmap_config bmp280_regmap_config; extern const struct regmap_config bmp280_regmap_config;
extern const struct regmap_config bmp380_regmap_config; extern const struct regmap_config bmp380_regmap_config;
extern const struct regmap_config bmp580_regmap_config;
/* Probe called from different transports */ /* Probe called from different transports */
int bmp280_common_probe(struct device *dev, int bmp280_common_probe(struct device *dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment