Commit 8d329309 authored by Angel Iglesias's avatar Angel Iglesias Committed by Jonathan Cameron

iio: pressure: bmp280: Add support for BMP380 sensor family

Adds compatibility with the new generation of this sensor, the BMP380.

Includes basic sensor initialization to do pressure and temp
measurements and allows tuning oversampling settings for each channel.

The compensation algorithms are adapted from the device datasheet and
the repository https://github.com/BoschSensortec/BMP3-Sensor-API.
Signed-off-by: default avatarAngel Iglesias <ang.iglesiasg@gmail.com>
Link: https://lore.kernel.org/r/f1da2a2f1bc5bb083f318335c23b4f3d9bb8e536.1663025017.git.ang.iglesiasg@gmail.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 18d1bb37
...@@ -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 pressure sensor I2C driver" tristate "Bosch Sensortec BMP180/BMP280/BMP380 pressure sensor I2C 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 and BMP280 Say yes here to build support for Bosch Sensortec BMP180, BMP280 and
pressure and temperature sensors. Also supports the BME280 with BMP380 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.
...@@ -19,6 +19,9 @@ static int bmp280_i2c_probe(struct i2c_client *client, ...@@ -19,6 +19,9 @@ static int bmp280_i2c_probe(struct i2c_client *client,
case BME280_CHIP_ID: case BME280_CHIP_ID:
regmap_config = &bmp280_regmap_config; regmap_config = &bmp280_regmap_config;
break; break;
case BMP380_CHIP_ID:
regmap_config = &bmp380_regmap_config;
break;
default: default:
return -EINVAL; return -EINVAL;
} }
...@@ -41,6 +44,7 @@ static const struct of_device_id bmp280_of_i2c_match[] = { ...@@ -41,6 +44,7 @@ static const struct of_device_id bmp280_of_i2c_match[] = {
{ .compatible = "bosch,bmp180", .data = (void *)BMP180_CHIP_ID }, { .compatible = "bosch,bmp180", .data = (void *)BMP180_CHIP_ID },
{ .compatible = "bosch,bmp280", .data = (void *)BMP280_CHIP_ID }, { .compatible = "bosch,bmp280", .data = (void *)BMP280_CHIP_ID },
{ .compatible = "bosch,bme280", .data = (void *)BME280_CHIP_ID }, { .compatible = "bosch,bme280", .data = (void *)BME280_CHIP_ID },
{ .compatible = "bosch,bmp380", .data = (void *)BMP380_CHIP_ID },
{ }, { },
}; };
MODULE_DEVICE_TABLE(of, bmp280_of_i2c_match); MODULE_DEVICE_TABLE(of, bmp280_of_i2c_match);
...@@ -50,6 +54,7 @@ static const struct i2c_device_id bmp280_i2c_id[] = { ...@@ -50,6 +54,7 @@ static const struct i2c_device_id bmp280_i2c_id[] = {
{"bmp180", BMP180_CHIP_ID }, {"bmp180", BMP180_CHIP_ID },
{"bmp280", BMP280_CHIP_ID }, {"bmp280", BMP280_CHIP_ID },
{"bme280", BME280_CHIP_ID }, {"bme280", BME280_CHIP_ID },
{"bmp380", BMP380_CHIP_ID },
{ }, { },
}; };
MODULE_DEVICE_TABLE(i2c, bmp280_i2c_id); MODULE_DEVICE_TABLE(i2c, bmp280_i2c_id);
......
...@@ -72,6 +72,49 @@ static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg) ...@@ -72,6 +72,49 @@ static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg)
} }
} }
static bool bmp380_is_writeable_reg(struct device *dev, unsigned int reg)
{
switch (reg) {
case BMP380_REG_CMD:
case BMP380_REG_CONFIG:
case BMP380_REG_FIFO_CONFIG_1:
case BMP380_REG_FIFO_CONFIG_2:
case BMP380_REG_FIFO_WATERMARK_LSB:
case BMP380_REG_FIFO_WATERMARK_MSB:
case BMP380_REG_POWER_CONTROL:
case BMP380_REG_INT_CONTROL:
case BMP380_REG_IF_CONFIG:
case BMP380_REG_ODR:
case BMP380_REG_OSR:
return true;
default:
return false;
}
}
static bool bmp380_is_volatile_reg(struct device *dev, unsigned int reg)
{
switch (reg) {
case BMP380_REG_TEMP_XLSB:
case BMP380_REG_TEMP_LSB:
case BMP380_REG_TEMP_MSB:
case BMP380_REG_PRESS_XLSB:
case BMP380_REG_PRESS_LSB:
case BMP380_REG_PRESS_MSB:
case BMP380_REG_SENSOR_TIME_XLSB:
case BMP380_REG_SENSOR_TIME_LSB:
case BMP380_REG_SENSOR_TIME_MSB:
case BMP380_REG_INT_STATUS:
case BMP380_REG_FIFO_DATA:
case BMP380_REG_STATUS:
case BMP380_REG_ERROR:
case BMP380_REG_EVENT:
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,
...@@ -83,3 +126,15 @@ const struct regmap_config bmp280_regmap_config = { ...@@ -83,3 +126,15 @@ const struct regmap_config bmp280_regmap_config = {
.volatile_reg = bmp280_is_volatile_reg, .volatile_reg = bmp280_is_volatile_reg,
}; };
EXPORT_SYMBOL_NS(bmp280_regmap_config, IIO_BMP280); EXPORT_SYMBOL_NS(bmp280_regmap_config, IIO_BMP280);
const struct regmap_config bmp380_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = BMP380_REG_CMD,
.cache_type = REGCACHE_RBTREE,
.writeable_reg = bmp380_is_writeable_reg,
.volatile_reg = bmp380_is_volatile_reg,
};
EXPORT_SYMBOL_NS(bmp380_regmap_config, IIO_BMP280);
...@@ -66,6 +66,9 @@ static int bmp280_spi_probe(struct spi_device *spi) ...@@ -66,6 +66,9 @@ static int bmp280_spi_probe(struct spi_device *spi)
case BME280_CHIP_ID: case BME280_CHIP_ID:
regmap_config = &bmp280_regmap_config; regmap_config = &bmp280_regmap_config;
break; break;
case BMP380_CHIP_ID:
regmap_config = &bmp380_regmap_config;
break;
default: default:
return -EINVAL; return -EINVAL;
} }
...@@ -92,6 +95,7 @@ static const struct of_device_id bmp280_of_spi_match[] = { ...@@ -92,6 +95,7 @@ static const struct of_device_id bmp280_of_spi_match[] = {
{ .compatible = "bosch,bmp181", }, { .compatible = "bosch,bmp181", },
{ .compatible = "bosch,bmp280", }, { .compatible = "bosch,bmp280", },
{ .compatible = "bosch,bme280", }, { .compatible = "bosch,bme280", },
{ .compatible = "bosch,bmp380", },
{ }, { },
}; };
MODULE_DEVICE_TABLE(of, bmp280_of_spi_match); MODULE_DEVICE_TABLE(of, bmp280_of_spi_match);
...@@ -101,6 +105,7 @@ static const struct spi_device_id bmp280_spi_id[] = { ...@@ -101,6 +105,7 @@ static const struct spi_device_id bmp280_spi_id[] = {
{ "bmp181", BMP180_CHIP_ID }, { "bmp181", BMP180_CHIP_ID },
{ "bmp280", BMP280_CHIP_ID }, { "bmp280", BMP280_CHIP_ID },
{ "bme280", BME280_CHIP_ID }, { "bme280", BME280_CHIP_ID },
{ "bmp380", BMP380_CHIP_ID },
{ } { }
}; };
MODULE_DEVICE_TABLE(spi, bmp280_spi_id); MODULE_DEVICE_TABLE(spi, bmp280_spi_id);
......
...@@ -3,6 +3,105 @@ ...@@ -3,6 +3,105 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/regmap.h> #include <linux/regmap.h>
/* BMP380 specific registers */
#define BMP380_REG_CMD 0x7E
#define BMP380_REG_CONFIG 0x1F
#define BMP380_REG_ODR 0x1D
#define BMP380_REG_OSR 0x1C
#define BMP380_REG_POWER_CONTROL 0x1B
#define BMP380_REG_IF_CONFIG 0x1A
#define BMP380_REG_INT_CONTROL 0x19
#define BMP380_REG_INT_STATUS 0x11
#define BMP380_REG_EVENT 0x10
#define BMP380_REG_STATUS 0x03
#define BMP380_REG_ERROR 0x02
#define BMP380_REG_ID 0x00
#define BMP380_REG_FIFO_CONFIG_1 0x18
#define BMP380_REG_FIFO_CONFIG_2 0x17
#define BMP380_REG_FIFO_WATERMARK_MSB 0x16
#define BMP380_REG_FIFO_WATERMARK_LSB 0x15
#define BMP380_REG_FIFO_DATA 0x14
#define BMP380_REG_FIFO_LENGTH_MSB 0x13
#define BMP380_REG_FIFO_LENGTH_LSB 0x12
#define BMP380_REG_SENSOR_TIME_MSB 0x0E
#define BMP380_REG_SENSOR_TIME_LSB 0x0D
#define BMP380_REG_SENSOR_TIME_XLSB 0x0C
#define BMP380_REG_TEMP_MSB 0x09
#define BMP380_REG_TEMP_LSB 0x08
#define BMP380_REG_TEMP_XLSB 0x07
#define BMP380_REG_PRESS_MSB 0x06
#define BMP380_REG_PRESS_LSB 0x05
#define BMP380_REG_PRESS_XLSB 0x04
#define BMP380_REG_CALIB_TEMP_START 0x31
#define BMP380_CALIB_REG_COUNT 21
#define BMP380_FILTER_MASK GENMASK(3, 1)
#define BMP380_FILTER_OFF 0
#define BMP380_FILTER_1X 1
#define BMP380_FILTER_3X 2
#define BMP380_FILTER_7X 3
#define BMP380_FILTER_15X 4
#define BMP380_FILTER_31X 5
#define BMP380_FILTER_63X 6
#define BMP380_FILTER_127X 7
#define BMP380_OSRS_TEMP_MASK GENMASK(5, 3)
#define BMP380_OSRS_PRESS_MASK GENMASK(2, 0)
#define BMP380_ODRS_MASK GENMASK(4, 0)
#define BMP380_ODRS_200HZ 0x00
#define BMP380_ODRS_100HZ 0x01
#define BMP380_ODRS_50HZ 0x02
#define BMP380_ODRS_25HZ 0x03
#define BMP380_ODRS_12_5HZ 0x04
#define BMP380_ODRS_6_25HZ 0x05
#define BMP380_ODRS_3_1HZ 0x06
#define BMP380_ODRS_1_5HZ 0x07
#define BMP380_ODRS_0_78HZ 0x08
#define BMP380_ODRS_0_39HZ 0x09
#define BMP380_ODRS_0_2HZ 0x0A
#define BMP380_ODRS_0_1HZ 0x0B
#define BMP380_ODRS_0_05HZ 0x0C
#define BMP380_ODRS_0_02HZ 0x0D
#define BMP380_ODRS_0_01HZ 0x0E
#define BMP380_ODRS_0_006HZ 0x0F
#define BMP380_ODRS_0_003HZ 0x10
#define BMP380_ODRS_0_0015HZ 0x11
#define BMP380_CTRL_SENSORS_MASK GENMASK(1, 0)
#define BMP380_CTRL_SENSORS_PRESS_EN BIT(0)
#define BMP380_CTRL_SENSORS_TEMP_EN BIT(1)
#define BMP380_MODE_MASK GENMASK(5, 4)
#define BMP380_MODE_SLEEP 0
#define BMP380_MODE_FORCED 1
#define BMP380_MODE_NORMAL 3
#define BMP380_MIN_TEMP -4000
#define BMP380_MAX_TEMP 8500
#define BMP380_MIN_PRES 3000000
#define BMP380_MAX_PRES 12500000
#define BMP380_CMD_NOOP 0x00
#define BMP380_CMD_EXTMODE_EN_MID 0x34
#define BMP380_CMD_FIFO_FLUSH 0xB0
#define BMP380_CMD_SOFT_RESET 0xB6
#define BMP380_STATUS_CMD_RDY_MASK BIT(4)
#define BMP380_STATUS_DRDY_PRESS_MASK BIT(5)
#define BMP380_STATUS_DRDY_TEMP_MASK BIT(6)
#define BMP380_ERR_FATAL_MASK BIT(0)
#define BMP380_ERR_CMD_MASK BIT(1)
#define BMP380_ERR_CONF_MASK BIT(2)
#define BMP380_TEMP_SKIPPED 0x800000
#define BMP380_PRESS_SKIPPED 0x800000
/* BMP280 specific registers */ /* BMP280 specific registers */
#define BMP280_REG_HUMIDITY_LSB 0xFE #define BMP280_REG_HUMIDITY_LSB 0xFE
#define BMP280_REG_HUMIDITY_MSB 0xFD #define BMP280_REG_HUMIDITY_MSB 0xFD
...@@ -99,6 +198,7 @@ ...@@ -99,6 +198,7 @@
#define BMP280_REG_RESET 0xE0 #define BMP280_REG_RESET 0xE0
#define BMP280_REG_ID 0xD0 #define BMP280_REG_ID 0xD0
#define BMP380_CHIP_ID 0x50
#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
...@@ -112,6 +212,7 @@ ...@@ -112,6 +212,7 @@
/* 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;
/* 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