Skip to contentSkip to conversation

Add support for BMP390 and various driver cleanups

PATCH Superseded Angel Iglesias 3 participants 10 messages Oct 15, 2023 – Oct 16, 2023 IIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add support for BMP390 and various driver cleanups

Add support for the Bosch BMP390 pressure sensors and includes minor driver code cleanups.
Patches 1 and 2 update I2C and SPI driver matching logic using newer helper functions available.
Patch 3 fixes minor coding style incoherences.
Patches 4 and 5 introduce support for the new BMP390 sensor allowing sensor families to have a list of known device IDs to improve detection

This patch series is aggregates patches from various series:
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/

Angel Iglesias (4):
iio: pressure: bmp280: Use spi_get_device_match_data()
iio: pressure: bmp280: Rearrange vars in reverse xmas tree order
iio: pressure: bmp280: Allow multiple chips id per family of devices
iio: pressure: bmp280: Add support for BMP390

Biju Das (1):
iio: pressure: bmp280: Use i2c_get_match_data()

 drivers/iio/pressure/bmp280-core.c | 56 ++++++++++++++++++++++++------
 drivers/iio/pressure/bmp280-i2c.c  |  8 ++---
 drivers/iio/pressure/bmp280-spi.c  | 10 ++----
 drivers/iio/pressure/bmp280.h      |  4 ++-
 4 files changed, 54 insertions(+), 24 deletions(-)

base-commit: 73006239ef2313f1986f86af86f8b06150a807e9

Signature · 1 line
2.42.0
#1 lore raw

PATCH 1/5 iio: pressure: bmp280: Use i2c_get_match_data()

From: Biju Das <[email protected]>

Replace device_get_match_data() and id lookup for retrieving match data by i2c_get_match_data().

drivers/iio/pressure/bmp280-i2c.c +1 -3
index dbe630ad05b5..b3e069730f97 100644
@@ -11,9 +11,7 @@ static int bmp280_i2c_probe(struct i2c_client *client)
 	const struct bmp280_chip_info *chip_info;
 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
 
-	chip_info = device_get_match_data(&client->dev);
-	if (!chip_info)
-		chip_info = (const struct bmp280_chip_info *) id->driver_data;
+	chip_info = i2c_get_match_data(client);
 
 	regmap = devm_regmap_init_i2c(client, chip_info->regmap_config);
 	if (IS_ERR(regmap)) {
Signature · 1 line
2.42.0
#2 lore raw

PATCH 2/5 iio: pressure: bmp280: Use spi_get_device_match_data()

In reply to Angel Iglesias

Use the spi_get_device_match_data() helper instead of device_get_match_data() and the fallback match_id logic.

drivers/iio/pressure/bmp280-spi.c +1 -3
index 1dff9bb7c4e9..2eed483a8cc4 100644
@@ -58,9 +58,7 @@ static int bmp280_spi_probe(struct spi_device *spi)
 		return ret;
 	}
 
-	chip_info = device_get_match_data(&spi->dev);
-	if (!chip_info)
-		chip_info = (const struct bmp280_chip_info *) id->driver_data;
+	chip_info = spi_get_device_match_data(spi);
 
 	regmap = devm_regmap_init(&spi->dev,
 				  &bmp280_regmap_bus,
Signature · 1 line
2.42.0
#3 lore raw

PATCH 3/5 iio: pressure: bmp280: Rearrange vars in reverse xmas tree order

In reply to Angel Iglesias

Small cleanup reordering local variable declarations following reverse christmas tree convention.

drivers/iio/pressure/bmp280-core.c +2 -2
index 6089f3f9d8f4..ea02a623bb58 100644
@@ -766,8 +766,8 @@ static const struct iio_info bmp280_info = {
 
 static int bmp280_chip_config(struct bmp280_data *data)
 {
-	u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) |
-		  FIELD_PREP(BMP280_OSRS_PRESS_MASK, data->oversampling_press + 1);
+	u8 osrs = FIELD_PREP(BMP280_OSRS_PRESS_MASK, data->oversampling_press + 1) |
+		  FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1);
 	int ret;
 
 	ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS,
drivers/iio/pressure/bmp280-i2c.c +2 -2
index b3e069730f97..34e3bc758493 100644
@@ -7,9 +7,9 @@
 
 static int bmp280_i2c_probe(struct i2c_client *client)
 {
-	struct regmap *regmap;
-	const struct bmp280_chip_info *chip_info;
 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
+	const struct bmp280_chip_info *chip_info;
+	struct regmap *regmap;
 
 	chip_info = i2c_get_match_data(client);
 
drivers/iio/pressure/bmp280-spi.c +2 -4
index 2eed483a8cc4..433d6fac83c4 100644
@@ -14,8 +14,7 @@
 static int bmp280_regmap_spi_write(void *context, const void *data,
                                    size_t count)
 {
-	struct device *dev = context;
-	struct spi_device *spi = to_spi_device(dev);
+	struct spi_device *spi = to_spi_device(context);
 	u8 buf[2];
 
 	memcpy(buf, data, 2);
@@ -31,8 +30,7 @@ static int bmp280_regmap_spi_write(void *context, const void *data,
 static int bmp280_regmap_spi_read(void *context, const void *reg,
                                   size_t reg_size, void *val, size_t val_size)
 {
-	struct device *dev = context;
-	struct spi_device *spi = to_spi_device(dev);
+	struct spi_device *spi = to_spi_device(context);
 
 	return spi_write_then_read(spi, reg, reg_size, val, val_size);
 }
Signature · 1 line
2.42.0
#5 lore raw

PATCH 4/5 iio: pressure: bmp280: Allow multiple chips id per family of devices

In reply to Angel Iglesias

Improve device detection in certain chip families known to have various chip ids.

drivers/iio/pressure/bmp280-core.c +42 -9
index ea02a623bb58..e3bb4d7906a9 100644
@@ -38,6 +38,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h> /* For irq_get_irq_data() */
 #include <linux/completion.h>
+#include <linux/overflow.h>
 #include <linux/pm_runtime.h>
 #include <linux/random.h>
 
@@ -794,10 +795,12 @@ static int bmp280_chip_config(struct bmp280_data *data)
 }
 
 static const int bmp280_oversampling_avail[] = { 1, 2, 4, 8, 16 };
+static const u8 bmp280_chip_ids[] = { BMP280_CHIP_ID };
 
 const struct bmp280_chip_info bmp280_chip_info = {
 	.id_reg = BMP280_REG_ID,
-	.chip_id = BMP280_CHIP_ID,
+	.chip_id = bmp280_chip_ids,
+	.num_chip_id = ARRAY_SIZE(bmp280_chip_ids),
 	.regmap_config = &bmp280_regmap_config,
 	.start_up_time = 2000,
 	.channels = bmp280_channels,
@@ -846,9 +849,12 @@ static int bme280_chip_config(struct bmp280_data *data)
 	return bmp280_chip_config(data);
 }
 
+static const u8 bme280_chip_ids[] = { BME280_CHIP_ID };
+
 const struct bmp280_chip_info bme280_chip_info = {
 	.id_reg = BMP280_REG_ID,
-	.chip_id = BME280_CHIP_ID,
+	.chip_id = bme280_chip_ids,
+	.num_chip_id = ARRAY_SIZE(bme280_chip_ids),
 	.regmap_config = &bmp280_regmap_config,
 	.start_up_time = 2000,
 	.channels = bmp280_channels,
@@ -1220,10 +1226,12 @@ static int bmp380_chip_config(struct bmp280_data *data)
 
 static const int bmp380_oversampling_avail[] = { 1, 2, 4, 8, 16, 32 };
 static const int bmp380_iir_filter_coeffs_avail[] = { 1, 2, 4, 8, 16, 32, 64, 128};
+static const u8 bmp380_chip_ids[] = { BMP380_CHIP_ID };
 
 const struct bmp280_chip_info bmp380_chip_info = {
 	.id_reg = BMP380_REG_ID,
-	.chip_id = BMP380_CHIP_ID,
+	.chip_id = bmp380_chip_ids,
+	.num_chip_id = ARRAY_SIZE(bmp380_chip_ids),
 	.regmap_config = &bmp380_regmap_config,
 	.start_up_time = 2000,
 	.channels = bmp380_channels,
@@ -1720,10 +1728,12 @@ static int bmp580_chip_config(struct bmp280_data *data)
 }
 
 static const int bmp580_oversampling_avail[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
+static const u8 bmp580_chip_ids[] = { BMP580_CHIP_ID, BMP580_CHIP_ID_ALT };
 
 const struct bmp280_chip_info bmp580_chip_info = {
 	.id_reg = BMP580_REG_CHIP_ID,
-	.chip_id = BMP580_CHIP_ID,
+	.chip_id = bmp580_chip_ids,
+	.num_chip_id = ARRAY_SIZE(bmp580_chip_ids),
 	.regmap_config = &bmp580_regmap_config,
 	.start_up_time = 2000,
 	.channels = bmp380_channels,
@@ -1983,10 +1993,12 @@ static int bmp180_chip_config(struct bmp280_data *data)
 
 static const int bmp180_oversampling_temp_avail[] = { 1 };
 static const int bmp180_oversampling_press_avail[] = { 1, 2, 4, 8 };
+static const u8 bmp180_chip_ids[] = { BMP180_CHIP_ID };
 
 const struct bmp280_chip_info bmp180_chip_info = {
 	.id_reg = BMP280_REG_ID,
-	.chip_id = BMP180_CHIP_ID,
+	.chip_id = bmp180_chip_ids,
+	.num_chip_id = ARRAY_SIZE(bmp180_chip_ids),
 	.regmap_config = &bmp180_regmap_config,
 	.start_up_time = 2000,
 	.channels = bmp280_channels,
@@ -2077,6 +2089,7 @@ int bmp280_common_probe(struct device *dev,
 	struct bmp280_data *data;
 	struct gpio_desc *gpiod;
 	unsigned int chip_id;
+	unsigned int i;
 	int ret;
 
 	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
@@ -2142,10 +2155,30 @@ int bmp280_common_probe(struct device *dev,
 	ret = regmap_read(regmap, data->chip_info->id_reg, &chip_id);
 	if (ret < 0)
 		return ret;
-	if (chip_id != data->chip_info->chip_id) {
-		dev_err(dev, "bad chip id: expected %x got %x\n",
-			data->chip_info->chip_id, chip_id);
-		return -EINVAL;
+
+	for (i = 0; i < data->chip_info->num_chip_id; i++) {
+		if (chip_id == data->chip_info->chip_id[i])
+			break;
+	}
+
+	if (i == data->chip_info->num_chip_id) {
+		size_t nbuf;
+		char *buf;
+
+		// 0x<id>, so four chars per number plus one space + ENDL
+		if (check_mul_overflow(data->chip_info->num_chip_id, 5, &nbuf))
+			return ret;
+
+		buf = kmalloc_array(data->chip_info->num_chip_id, 5, GFP_KERNEL);
+		if (!buf)
+			return ret;
+
+		for (i = 0; i < data->chip_info->num_chip_id; i++)
+			snprintf(&buf[i*5], nbuf - i*5, "0x%x ", data->chip_info->chip_id[i]);
+
+		dev_err(dev, "bad chip id: expected one of [ %s ] got 0x%x\n", buf, chip_id);
+		kfree(buf);
+		return ret;
 	}
 
 	if (data->chip_info->preinit) {
drivers/iio/pressure/bmp280.h +2 -1
index 5c0563ce7572..a230fcfc4a85 100644
@@ -418,7 +418,8 @@ struct bmp280_data {
 
 struct bmp280_chip_info {
 	unsigned int id_reg;
-	const unsigned int chip_id;
+	const u8 *chip_id;
+	int num_chip_id;
 
 	const struct regmap_config *regmap_config;
 
Signature · 1 line
2.42.0
#8 lore raw

PATCH 5/5 iio: pressure: bmp280: Add support for BMP390

In reply to Angel Iglesias

Add BMP390 device ID to the supported IDs on bmp380 sensor family

drivers/iio/pressure/bmp280-core.c +2 -1
index e3bb4d7906a9..d2345956ebc8 100644
@@ -13,6 +13,7 @@
  * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp280-ds001.pdf
  * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme280-ds002.pdf
  * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp388-ds001.pdf
+ * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp390-ds002.pdf
  * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp581-ds004.pdf
  *
  * Notice:
@@ -1226,7 +1227,7 @@ static int bmp380_chip_config(struct bmp280_data *data)
 
 static const int bmp380_oversampling_avail[] = { 1, 2, 4, 8, 16, 32 };
 static const int bmp380_iir_filter_coeffs_avail[] = { 1, 2, 4, 8, 16, 32, 64, 128};
-static const u8 bmp380_chip_ids[] = { BMP380_CHIP_ID };
+static const u8 bmp380_chip_ids[] = { BMP380_CHIP_ID, BMP390_CHIP_ID };
 
 const struct bmp280_chip_info bmp380_chip_info = {
 	.id_reg = BMP380_REG_ID,
drivers/iio/pressure/bmp280.h +1 -0
index a230fcfc4a85..2971bf58f802 100644
@@ -292,6 +292,7 @@
 #define BMP580_CHIP_ID_ALT		0x51
 #define BMP180_CHIP_ID			0x55
 #define BMP280_CHIP_ID			0x58
+#define BMP390_CHIP_ID			0x60
 #define BME280_CHIP_ID			0x60
 #define BMP280_SOFT_RESET_VAL		0xB6
 
Signature · 1 line
2.42.0
#6 lore raw

Re: [PATCH 4/5] iio: pressure: bmp280: Allow multiple chips id per family of devices

In reply to Angel Iglesias
Quoted 2 lines · Angel Iglesias

Improve device detection in certain chip families known to have various chip ids.

...

Quoted 1 line

+#include <linux/overflow.h>

Probably you don't need this, see below.

...

drivers/iio/pressure/bmp280-core.c int bmp280_common_probe(struct device *dev, · line 2170

Quoted 11 lines
drivers/iio/pressure/bmp280-core.c +7 -0
 	ret = regmap_read(regmap, data->chip_info->id_reg, &chip_id);
 	if (ret < 0)
 		return ret;
 
+	if (i == data->chip_info->num_chip_id) {
+		size_t nbuf;
+		char *buf;
+
+		// 0x<id>, so four chars per number plus one space + ENDL
+		if (check_mul_overflow(data->chip_info->num_chip_id, 5, &nbuf))
+			return ret;

First of all, it _implicitly_ returns 0 here...

drivers/iio/pressure/bmp280-core.c int bmp280_common_probe(struct device *dev, · line 2174

Quoted 3 lines
drivers/iio/pressure/bmp280-core.c +3 -0
+		buf = kmalloc_array(data->chip_info->num_chip_id, 5, GFP_KERNEL);
+		if (!buf)
+			return ret;

...and here.

Second, kmalloc_array() has that check inside.

Third, define this magic 5 either as strlen(), or a constant (in latter case with the comment of its meaning).

drivers/iio/pressure/bmp280-core.c int bmp280_common_probe(struct device *dev, · line 2177

Quoted 2 lines
drivers/iio/pressure/bmp280-core.c +2 -0
+		for (i = 0; i < data->chip_info->num_chip_id; i++)
+			snprintf(&buf[i*5], nbuf - i*5, "0x%x ", data->chip_info->chip_id[i]);

Fourth, use incremental position, i.e. use retuned value from snprintf().

drivers/iio/pressure/bmp280-core.c int bmp280_common_probe(struct device *dev,

Quoted 4 lines
drivers/iio/pressure/bmp280-core.c +3 -0
+		dev_err(dev, "bad chip id: expected one of [ %s ] got 0x%x\n", buf, chip_id);
+		kfree(buf);
 
+		return ret;

As per "first" and "second" above.

Quoted 1 line

}

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on the v1 series
#9 lore raw
In reply to Angel Iglesias
Quoted 8 lines · Angel Iglesias

Add support for the Bosch BMP390 pressure sensors and includes minor driver code cleanups.
Patches 1 and 2 update I2C and SPI driver matching logic using newer helper functions available.
Patch 3 fixes minor coding style incoherences.
Patches 4 and 5 introduce support for the new BMP390 sensor allowing sensor families to have a list of known device IDs to improve detection

Quoted 4 lines

This patch series is aggregates patches from various series:
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/

For the patches 1-3,

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#7 lore raw

Re: [PATCH 4/5] iio: pressure: bmp280: Allow multiple chips id per family of devices

In reply to Angel Iglesias
Quoted 4 lines · On Sun, 15 Oct 2023 17:16:26 +0200 Angel Iglesias <[email protected]>…

Improve device detection in certain chip families known to have various chip ids.

A few minor things inline.

J

Quoted 100 lines
drivers/iio/pressure/bmp280-core.c +19 -9
index ea02a623bb58..e3bb4d7906a9 100644
@@ -38,6 +38,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h> /* For irq_get_irq_data() */
 #include <linux/completion.h>
+#include <linux/overflow.h>
 #include <linux/pm_runtime.h>
 #include <linux/random.h>
 
@@ -794,10 +795,12 @@ static int bmp280_chip_config(struct bmp280_data *data)
 }
 
 static const int bmp280_oversampling_avail[] = { 1, 2, 4, 8, 16 };
+static const u8 bmp280_chip_ids[] = { BMP280_CHIP_ID };
 
 const struct bmp280_chip_info bmp280_chip_info = {
 	.id_reg = BMP280_REG_ID,
-	.chip_id = BMP280_CHIP_ID,
+	.chip_id = bmp280_chip_ids,
+	.num_chip_id = ARRAY_SIZE(bmp280_chip_ids),
 	.regmap_config = &bmp280_regmap_config,
 	.start_up_time = 2000,
 	.channels = bmp280_channels,
@@ -846,9 +849,12 @@ static int bme280_chip_config(struct bmp280_data *data)
 	return bmp280_chip_config(data);
 }
 
+static const u8 bme280_chip_ids[] = { BME280_CHIP_ID };
+
 const struct bmp280_chip_info bme280_chip_info = {
 	.id_reg = BMP280_REG_ID,
-	.chip_id = BME280_CHIP_ID,
+	.chip_id = bme280_chip_ids,
+	.num_chip_id = ARRAY_SIZE(bme280_chip_ids),
 	.regmap_config = &bmp280_regmap_config,
 	.start_up_time = 2000,
 	.channels = bmp280_channels,
@@ -1220,10 +1226,12 @@ static int bmp380_chip_config(struct bmp280_data *data)
 
 static const int bmp380_oversampling_avail[] = { 1, 2, 4, 8, 16, 32 };
 static const int bmp380_iir_filter_coeffs_avail[] = { 1, 2, 4, 8, 16, 32, 64, 128};
+static const u8 bmp380_chip_ids[] = { BMP380_CHIP_ID };
 
 const struct bmp280_chip_info bmp380_chip_info = {
 	.id_reg = BMP380_REG_ID,
-	.chip_id = BMP380_CHIP_ID,
+	.chip_id = bmp380_chip_ids,
+	.num_chip_id = ARRAY_SIZE(bmp380_chip_ids),
 	.regmap_config = &bmp380_regmap_config,
 	.start_up_time = 2000,
 	.channels = bmp380_channels,
@@ -1720,10 +1728,12 @@ static int bmp580_chip_config(struct bmp280_data *data)
 }
 
 static const int bmp580_oversampling_avail[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
+static const u8 bmp580_chip_ids[] = { BMP580_CHIP_ID, BMP580_CHIP_ID_ALT };
 
 const struct bmp280_chip_info bmp580_chip_info = {
 	.id_reg = BMP580_REG_CHIP_ID,
-	.chip_id = BMP580_CHIP_ID,
+	.chip_id = bmp580_chip_ids,
+	.num_chip_id = ARRAY_SIZE(bmp580_chip_ids),
 	.regmap_config = &bmp580_regmap_config,
 	.start_up_time = 2000,
 	.channels = bmp380_channels,
@@ -1983,10 +1993,12 @@ static int bmp180_chip_config(struct bmp280_data *data)
 
 static const int bmp180_oversampling_temp_avail[] = { 1 };
 static const int bmp180_oversampling_press_avail[] = { 1, 2, 4, 8 };
+static const u8 bmp180_chip_ids[] = { BMP180_CHIP_ID };
 
 const struct bmp280_chip_info bmp180_chip_info = {
 	.id_reg = BMP280_REG_ID,
-	.chip_id = BMP180_CHIP_ID,
+	.chip_id = bmp180_chip_ids,
+	.num_chip_id = ARRAY_SIZE(bmp180_chip_ids),
 	.regmap_config = &bmp180_regmap_config,
 	.start_up_time = 2000,
 	.channels = bmp280_channels,
@@ -2077,6 +2089,7 @@ int bmp280_common_probe(struct device *dev,
 	struct bmp280_data *data;
 	struct gpio_desc *gpiod;
 	unsigned int chip_id;
+	unsigned int i;
 	int ret;
 
 	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
@@ -2142,10 +2155,30 @@ int bmp280_common_probe(struct device *dev,
 	ret = regmap_read(regmap, data->chip_info->id_reg, &chip_id);
 	if (ret < 0)
 		return ret;
-	if (chip_id != data->chip_info->chip_id) {
-		dev_err(dev, "bad chip id: expected %x got %x\n",
-			data->chip_info->chip_id, chip_id);
-		return -EINVAL;
+

drivers/iio/pressure/bmp280-core.c int bmp280_common_probe(struct device *dev, · line 2168

Quoted 10 lines
drivers/iio/pressure/bmp280-core.c +10 -0
+	for (i = 0; i < data->chip_info->num_chip_id; i++) {
+		if (chip_id == data->chip_info->chip_id[i])
+			break;
+	}
+
+	if (i == data->chip_info->num_chip_id) {
+		size_t nbuf;
+		char *buf;
+
+		// 0x<id>, so four chars per number plus one space + ENDL

Trivial but /* */ comment syntax for IIO please.

drivers/iio/pressure/bmp280-core.c int bmp280_common_probe(struct device *dev, · line 2177

Quoted 9 lines
drivers/iio/pressure/bmp280-core.c +9 -0
+		if (check_mul_overflow(data->chip_info->num_chip_id, 5, &nbuf))
+			return ret;
+
+		buf = kmalloc_array(data->chip_info->num_chip_id, 5, GFP_KERNEL);
+		if (!buf)
+			return ret;
+
+		for (i = 0; i < data->chip_info->num_chip_id; i++)
+			snprintf(&buf[i*5], nbuf - i*5, "0x%x ", data->chip_info->chip_id[i]);

I'd uses multiple dev_err() lines and skip this complexity. Doesn't need to be as pretty as this given it's an error reprot :) However, we should support fallback compatibles. So this should be a dev_warn at most and we should go on with whatever firmware said. Note the original code didn't do this (I used to get this wrong in reviews) but it would be good to improve it whilst here.

drivers/iio/pressure/bmp280-core.c int bmp280_common_probe(struct device *dev, · line 2179

Quoted 2 lines
drivers/iio/pressure/bmp280-core.c +2 -0
+
+		dev_err(dev, "bad chip id: expected one of [ %s ] got 0x%x\n", buf, chip_id);

In probe so dev_err_probe() preferred and with the autocleanup this can be return dev_err_probe()

drivers/iio/pressure/bmp280-core.c int bmp280_common_probe(struct device *dev, · line 2180

Quoted 1 line
drivers/iio/pressure/bmp280-core.c +1 -0
+		kfree(buf);

The new autocleanup stuff is nice for this sort of case.

char *buf __free(kfree) = NULL;

Quoted 18 lines
drivers/iio/pressure/bmp280-core.c +1 -0
+		return ret;
 	}
 
 	if (data->chip_info->preinit) {
drivers/iio/pressure/bmp280.h +2 -1
index 5c0563ce7572..a230fcfc4a85 100644
@@ -418,7 +418,8 @@ struct bmp280_data {
 
 struct bmp280_chip_info {
 	unsigned int id_reg;
-	const unsigned int chip_id;
+	const u8 *chip_id;
+	int num_chip_id;
 
 	const struct regmap_config *regmap_config;
 
maintainer
#4 lore raw

Re: [PATCH 3/5] iio: pressure: bmp280: Rearrange vars in reverse xmas tree order

In reply to Angel Iglesias
Quoted 10 lines · On Sun, 15 Oct 2023 17:16:25 +0200 Angel Iglesias <[email protected]>…

Small cleanup reordering local variable declarations following reverse christmas tree convention.

drivers/iio/pressure/bmp280-core.c +0 -0
index 6089f3f9d8f4..ea02a623bb58 100644

drivers/iio/pressure/bmp280-core.c static const struct iio_info bmp280_info = { · line 770

Quoted 7 lines
drivers/iio/pressure/bmp280-core.c +2 -2
@@ -766,8 +766,8 @@ static const struct iio_info bmp280_info = {
 
 static int bmp280_chip_config(struct bmp280_data *data)
 {
-	u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) |
-		  FIELD_PREP(BMP280_OSRS_PRESS_MASK, data->oversampling_press + 1);
+	u8 osrs = FIELD_PREP(BMP280_OSRS_PRESS_MASK, data->oversampling_press + 1) |
+		  FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1);

For fields within a register, don't bother.
Normally the order is dictated by someone reading the fields on a datasheet. Feels like reorganzing them is just noise to me.

The rest look like good little tidy ups to me.

Quoted 43 lines
drivers/iio/pressure/bmp280-core.c +0 -0
 	int ret;
 
 	ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS,
drivers/iio/pressure/bmp280-i2c.c +2 -2
index b3e069730f97..34e3bc758493 100644
@@ -7,9 +7,9 @@
 
 static int bmp280_i2c_probe(struct i2c_client *client)
 {
-	struct regmap *regmap;
-	const struct bmp280_chip_info *chip_info;
 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
+	const struct bmp280_chip_info *chip_info;
+	struct regmap *regmap;
 
 	chip_info = i2c_get_match_data(client);
 
drivers/iio/pressure/bmp280-spi.c +2 -4
index 2eed483a8cc4..433d6fac83c4 100644
@@ -14,8 +14,7 @@
 static int bmp280_regmap_spi_write(void *context, const void *data,
                                    size_t count)
 {
-	struct device *dev = context;
-	struct spi_device *spi = to_spi_device(dev);
+	struct spi_device *spi = to_spi_device(context);
 	u8 buf[2];
 
 	memcpy(buf, data, 2);
@@ -31,8 +30,7 @@ static int bmp280_regmap_spi_write(void *context, const void *data,
 static int bmp280_regmap_spi_read(void *context, const void *reg,
                                   size_t reg_size, void *val, size_t val_size)
 {
-	struct device *dev = context;
-	struct spi_device *spi = to_spi_device(dev);
+	struct spi_device *spi = to_spi_device(context);
 
 	return spi_write_then_read(spi, reg, reg_size, val, val_size);
 }