This patchset adds support for the new pressure sensors BMP580 extending
the bmp280 driver.
Patch 1 introduces a variant enumeration and refactors sensor verification
logic adding a chip_id field to the chip_info struct. This change is
required because BMP380 and BMP580 have the same chip_id and values would
collide using the chip_id as the driver_data value.
Patch 2 introduces new preinit callback and unifies init logic across all
supported variants.
Patch 3 extends the bmp280 driver with the new logic to read measurements
and configure the operation parameters for the BMP580 sensors.
Patch 4 updates the devicetree binding docs with the new sensor id.
Patch 5 adds the NVMEM operations to read and program the NVM user range
contained in the non-volatile memory of the BMP580 sensors.
Changes in V2:
* For patch 3, fixed missing retcodes reported by the kernel test robot.
* For patch 5, fixed logic paths that left the sensor mutex locked
reported by the kernel test robot.
Angel Iglesias (5):
iio: pressure: bmp280: Add enumeration to handle chip variants
iio: pressure: bmp280: Add preinit callback
iio: pressure: bmp280: Add support for new sensor BMP580
dt-bindings: iio: pressure: bmp085: Add BMP580 compatible string
iio: pressure: bmp280: Add nvmem operations for BMP580
.../bindings/iio/pressure/bmp085.yaml | 2 +
drivers/iio/pressure/Kconfig | 6 +-
drivers/iio/pressure/bmp280-core.c | 617 +++++++++++++++++-
drivers/iio/pressure/bmp280-i2c.c | 33 +-
drivers/iio/pressure/bmp280-regmap.c | 60 ++
drivers/iio/pressure/bmp280-spi.c | 23 +-
drivers/iio/pressure/bmp280.h | 115 ++++
7 files changed, 815 insertions(+), 41 deletions(-)
base-commit: e807541c2b273677e82ef50b5747ec7ae7d652b9
--
2.39.0
Adds preinit callback to execute operations on probe before applying
initial configuration.
Signed-off-by: Angel Iglesias <[email protected]>
diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index 46959a91408f..c37cf2caec68 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -217,6 +217,7 @@ struct bmp280_chip_info {
int (*read_press)(struct bmp280_data *, int *, int *);
int (*read_humid)(struct bmp280_data *, int *, int *);
int (*read_calib)(struct bmp280_data *);
+ int (*preinit)(struct bmp280_data *);
};
/*
@@ -935,6 +936,7 @@ static const struct bmp280_chip_info bmp280_chip_info = {
.read_temp = bmp280_read_temp,
.read_press = bmp280_read_press,
.read_calib = bmp280_read_calib,
+ .preinit = NULL,
};
static int bme280_chip_config(struct bmp280_data *data)
@@ -979,6 +981,7 @@ static const struct bmp280_chip_info bme280_chip_info = {
.read_press = bmp280_read_press,
.read_humid = bmp280_read_humid,
.read_calib = bme280_read_calib,
+ .preinit = NULL,
};
/*
@@ -1220,6 +1223,12 @@ static const int bmp380_odr_table[][2] = {
[BMP380_ODR_0_0015HZ] = {0, 1526},
};
+static int bmp380_preinit(struct bmp280_data *data)
+{
+ /* BMP3xx requires soft-reset as part of initialization */
+ return bmp380_cmd(data, BMP380_CMD_SOFT_RESET);
+}
+
static int bmp380_chip_config(struct bmp280_data *data)
{
bool change = false, aux;
@@ -1349,6 +1358,7 @@ static const struct bmp280_chip_info bmp380_chip_info = {
.read_temp = bmp380_read_temp,
.read_press = bmp380_read_press,
.read_calib = bmp380_read_calib,
+ .preinit = bmp380_preinit,
};
static int bmp180_measure(struct bmp280_data *data, u8 ctrl_meas)
@@ -1604,6 +1614,7 @@ static const struct bmp280_chip_info bmp180_chip_info = {
.read_temp = bmp180_read_temp,
.read_press = bmp180_read_press,
.read_calib = bmp180_read_calib,
+ .preinit = NULL,
};
static irqreturn_t bmp085_eoc_irq(int irq, void *d)
@@ -1762,9 +1773,13 @@ int bmp280_common_probe(struct device *dev,
return -EINVAL;
}
- /* BMP3xx requires soft-reset as part of initialization */
- if (chip_id == BMP380_CHIP_ID) {
- ret = bmp380_cmd(data, BMP380_CMD_SOFT_RESET);
+ /*
+ * Some chips like the BMP3xx have preinit tasks to run
+ * before applying the initial configuration.
+ */
+ if (data->chip_info->preinit) {
+ ret = data->chip_info->preinit(data);
+ dev_err(dev, "error running preinit tasks");
if (ret < 0)
return ret;
}
--
2.39.0
On Mon, Dec 26, 2022 at 03:29:21PM +0100, Angel Iglesias wrote:
> Adds preinit callback to execute operations on probe before applying
> initial configuration.
...
> @@ -935,6 +936,7 @@ static const struct bmp280_chip_info bmp280_chip_info = {
> .read_temp = bmp280_read_temp,
> .read_press = bmp280_read_press,
> .read_calib = bmp280_read_calib,
> + .preinit = NULL,
> };
>
> static int bme280_chip_config(struct bmp280_data *data)
> @@ -979,6 +981,7 @@ static const struct bmp280_chip_info bme280_chip_info = {
> .read_press = bmp280_read_press,
> .read_humid = bmp280_read_humid,
> .read_calib = bme280_read_calib,
> + .preinit = NULL,
> };
Useless changes.
...
> @@ -1604,6 +1614,7 @@ static const struct bmp280_chip_info bmp180_chip_info = {
> .read_temp = bmp180_read_temp,
> .read_press = bmp180_read_press,
> .read_calib = bmp180_read_calib,
> + .preinit = NULL,
> };
Ditto.
...
> + /*
> + * Some chips like the BMP3xx have preinit tasks to run
> + * before applying the initial configuration.
> + */
> + if (data->chip_info->preinit) {
> + ret = data->chip_info->preinit(data);
> + dev_err(dev, "error running preinit tasks");
Huh?! I guess you wanted
> if (ret < 0)
> return ret;
if (ret < 0)
return dev_err_probe(...);
> }
--
With Best Regards,
Andy Shevchenko
On Mon, 26 Dec 2022 15:29:21 +0100
Angel Iglesias <[email protected]> wrote:
> Adds preinit callback to execute operations on probe before applying
> initial configuration.
>
> Signed-off-by: Angel Iglesias <[email protected]>
>
> diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
> index 46959a91408f..c37cf2caec68 100644
> --- a/drivers/iio/pressure/bmp280-core.c
> +++ b/drivers/iio/pressure/bmp280-core.c
> @@ -217,6 +217,7 @@ struct bmp280_chip_info {
> int (*read_press)(struct bmp280_data *, int *, int *);
> int (*read_humid)(struct bmp280_data *, int *, int *);
> int (*read_calib)(struct bmp280_data *);
> + int (*preinit)(struct bmp280_data *);
> };
>
> /*
> @@ -935,6 +936,7 @@ static const struct bmp280_chip_info bmp280_chip_info = {
> .read_temp = bmp280_read_temp,
> .read_press = bmp280_read_press,
> .read_calib = bmp280_read_calib,
> + .preinit = NULL,
C standard guarantees those are set to NULL anyway + the default is obvious.
Hence don't set them to NULL, just leave the automatic initialization of
unspecified structure elements to handle it for you.
> };
>
> static int bme280_chip_config(struct bmp280_data *data)
> @@ -979,6 +981,7 @@ static const struct bmp280_chip_info bme280_chip_info = {
> .read_press = bmp280_read_press,
> .read_humid = bmp280_read_humid,
> .read_calib = bme280_read_calib,
> + .preinit = NULL,
> };
>
> /*
> @@ -1220,6 +1223,12 @@ static const int bmp380_odr_table[][2] = {
> [BMP380_ODR_0_0015HZ] = {0, 1526},
> };
>
> +static int bmp380_preinit(struct bmp280_data *data)
> +{
> + /* BMP3xx requires soft-reset as part of initialization */
> + return bmp380_cmd(data, BMP380_CMD_SOFT_RESET);
> +}
> +
> static int bmp380_chip_config(struct bmp280_data *data)
> {
> bool change = false, aux;
> @@ -1349,6 +1358,7 @@ static const struct bmp280_chip_info bmp380_chip_info = {
> .read_temp = bmp380_read_temp,
> .read_press = bmp380_read_press,
> .read_calib = bmp380_read_calib,
> + .preinit = bmp380_preinit,
> };
>
> static int bmp180_measure(struct bmp280_data *data, u8 ctrl_meas)
> @@ -1604,6 +1614,7 @@ static const struct bmp280_chip_info bmp180_chip_info = {
> .read_temp = bmp180_read_temp,
> .read_press = bmp180_read_press,
> .read_calib = bmp180_read_calib,
> + .preinit = NULL,
> };
>
> static irqreturn_t bmp085_eoc_irq(int irq, void *d)
> @@ -1762,9 +1773,13 @@ int bmp280_common_probe(struct device *dev,
> return -EINVAL;
> }
>
> - /* BMP3xx requires soft-reset as part of initialization */
> - if (chip_id == BMP380_CHIP_ID) {
> - ret = bmp380_cmd(data, BMP380_CMD_SOFT_RESET);
> + /*
> + * Some chips like the BMP3xx have preinit tasks to run
> + * before applying the initial configuration.
> + */
I would drop this comment. It's kind of obvious that some devices need you
to call something here - otherwise why have the clearly optional callback?
The specific BMP3xx requirements are well commented in your new callback above
so don't want to be here as well.
> + if (data->chip_info->preinit) {
> + ret = data->chip_info->preinit(data);
> + dev_err(dev, "error running preinit tasks");
Error message printed on success...
> if (ret < 0)
> return ret;
return dev_err_probe(dev, ret, "error running preinit tasks");
> }
On Tue, 2022-12-27 at 23:41 +0200, Andy Shevchenko wrote:
> On Mon, Dec 26, 2022 at 03:29:21PM +0100, Angel Iglesias wrote:
> > Adds preinit callback to execute operations on probe before applying
> > initial configuration.
>
> ...
>
> > @@ -935,6 +936,7 @@ static const struct bmp280_chip_info bmp280_chip_info =
> > {
> > .read_temp = bmp280_read_temp,
> > .read_press = bmp280_read_press,
> > .read_calib = bmp280_read_calib,
> > + .preinit = NULL,
> > };
> >
> > static int bme280_chip_config(struct bmp280_data *data)
> > @@ -979,6 +981,7 @@ static const struct bmp280_chip_info bme280_chip_info =
> > {
> > .read_press = bmp280_read_press,
> > .read_humid = bmp280_read_humid,
> > .read_calib = bme280_read_calib,
> > + .preinit = NULL,
> > };
>
> Useless changes.
>
> ...
>
> > @@ -1604,6 +1614,7 @@ static const struct bmp280_chip_info bmp180_chip_info
> > = {
> > .read_temp = bmp180_read_temp,
> > .read_press = bmp180_read_press,
> > .read_calib = bmp180_read_calib,
> > + .preinit = NULL,
> > };
>
> Ditto.
>
> ...
>
> > + /*
> > + * Some chips like the BMP3xx have preinit tasks to run
> > + * before applying the initial configuration.
> > + */
> > + if (data->chip_info->preinit) {
> > + ret = data->chip_info->preinit(data);
>
> > + dev_err(dev, "error running preinit tasks");
>
> Huh?! I guess you wanted
The dangers of copying paste and rushing things etc. Sorry for this brain fart!
Thanks for your time,
Angel
> > if (ret < 0)
> > return ret;
>
> if (ret < 0)
> return dev_err_probe(...);
>
> > }
>
On Fri, 2022-12-30 at 18:18 +0000, Jonathan Cameron wrote:
> On Mon, 26 Dec 2022 15:29:21 +0100
> Angel Iglesias <[email protected]> wrote:
>
> > Adds preinit callback to execute operations on probe before applying
> > initial configuration.
> >
> > Signed-off-by: Angel Iglesias <[email protected]>
> >
> > diff --git a/drivers/iio/pressure/bmp280-core.c
> > b/drivers/iio/pressure/bmp280-core.c
> > index 46959a91408f..c37cf2caec68 100644
> > --- a/drivers/iio/pressure/bmp280-core.c
> > +++ b/drivers/iio/pressure/bmp280-core.c
> > @@ -217,6 +217,7 @@ struct bmp280_chip_info {
> > int (*read_press)(struct bmp280_data *, int *, int *);
> > int (*read_humid)(struct bmp280_data *, int *, int *);
> > int (*read_calib)(struct bmp280_data *);
> > + int (*preinit)(struct bmp280_data *);
> > };
> >
> > /*
> > @@ -935,6 +936,7 @@ static const struct bmp280_chip_info bmp280_chip_info =
> > {
> > .read_temp = bmp280_read_temp,
> > .read_press = bmp280_read_press,
> > .read_calib = bmp280_read_calib,
> > + .preinit = NULL,
> C standard guarantees those are set to NULL anyway + the default is obvious.
> Hence don't set them to NULL, just leave the automatic initialization of
> unspecified structure elements to handle it for you.
OK! Note to self: compiler knows best!
> > };
> >
> > static int bme280_chip_config(struct bmp280_data *data)
> > @@ -979,6 +981,7 @@ static const struct bmp280_chip_info bme280_chip_info =
> > {
> > .read_press = bmp280_read_press,
> > .read_humid = bmp280_read_humid,
> > .read_calib = bme280_read_calib,
> > + .preinit = NULL,
> > };
> >
> > /*
> > @@ -1220,6 +1223,12 @@ static const int bmp380_odr_table[][2] = {
> > [BMP380_ODR_0_0015HZ] = {0, 1526},
> > };
> >
> > +static int bmp380_preinit(struct bmp280_data *data)
> > +{
> > + /* BMP3xx requires soft-reset as part of initialization */
> > + return bmp380_cmd(data, BMP380_CMD_SOFT_RESET);
> > +}
> > +
> > static int bmp380_chip_config(struct bmp280_data *data)
> > {
> > bool change = false, aux;
> > @@ -1349,6 +1358,7 @@ static const struct bmp280_chip_info bmp380_chip_info
> > = {
> > .read_temp = bmp380_read_temp,
> > .read_press = bmp380_read_press,
> > .read_calib = bmp380_read_calib,
> > + .preinit = bmp380_preinit,
> > };
> >
> > static int bmp180_measure(struct bmp280_data *data, u8 ctrl_meas)
> > @@ -1604,6 +1614,7 @@ static const struct bmp280_chip_info bmp180_chip_info
> > = {
> > .read_temp = bmp180_read_temp,
> > .read_press = bmp180_read_press,
> > .read_calib = bmp180_read_calib,
> > + .preinit = NULL,
> > };
> >
> > static irqreturn_t bmp085_eoc_irq(int irq, void *d)
> > @@ -1762,9 +1773,13 @@ int bmp280_common_probe(struct device *dev,
> > return -EINVAL;
> > }
> >
> > - /* BMP3xx requires soft-reset as part of initialization */
> > - if (chip_id == BMP380_CHIP_ID) {
> > - ret = bmp380_cmd(data, BMP380_CMD_SOFT_RESET);
> > + /*
> > + * Some chips like the BMP3xx have preinit tasks to run
> > + * before applying the initial configuration.
> > + */
> I would drop this comment. It's kind of obvious that some devices need you
> to call something here - otherwise why have the clearly optional callback?
> The specific BMP3xx requirements are well commented in your new callback above
> so don't want to be here as well.
>
> > + if (data->chip_info->preinit) {
> > + ret = data->chip_info->preinit(data);
> > + dev_err(dev, "error running preinit tasks");
>
> Error message printed on success...
Yup, sorry about that...
>
> > if (ret < 0)
> > return ret;
>
> return dev_err_probe(dev, ret, "error running preinit
> tasks");
>
> > }
>
Thanks for your time!
Angel