Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: imu: bmi270: use dev_warn for unexpected chip id
@ 2026-03-16 23:11 Rodrigo Gobbi
  2026-03-17  7:14 ` Andy Shevchenko
  2026-03-17 20:47 ` Jonathan Cameron
  0 siblings, 2 replies; 3+ messages in thread
From: Rodrigo Gobbi @ 2026-03-16 23:11 UTC (permalink / raw)
  To: lanzano.alex, jic23, dlechner, nuno.sa, andy, gustavograzs
  Cc: ~lkcamp/patches, linux-iio, linux-kernel

An unexpected chip id read from hardware indicates a potential
failure for detecting id, which needs a more appropriate level
of verbosity.

Signed-off-by: Rodrigo Gobbi <rodrigo.gobbi.7@gmail.com>
---
I was exploring Bosch BMI270 driver and noticed a possible dev_info usage that might
not be appropriate it regarding its verbosity level. Let's consider that probe definition
at [1], used by [2] spi version and [3] i2 version.
The i2c or spi callers will fill chip_info and then, probe will try to validate it at _init function:

// drivers/iio/imu/bmi270/bmi270_core.c
int bmi270_core_probe(struct device *dev, struct regmap *regmap,
		      const struct bmi270_chip_info *chip_info)          
    data->chip_info = chip_info;
...
	ret = bmi270_chip_init(data);
....

static int bmi270_chip_init(struct bmi270_data *data)
{
	int ret;

	ret = bmi270_validate_chip_id(data);
	if (ret)
        return ret;
....

from init, chipid will be read from hardware but if the value is not expected with
the one from the caller, i2c or spi, it will trigger a dev_info and not a warning:

// valid ids for i2c and spi
#define BMI260_CHIP_ID_VAL				0x27
#define BMI270_CHIP_ID_VAL				0x24

static int bmi270_validate_chip_id(struct bmi270_data *data)
{
	int chip_id;
	int ret;
	struct device *dev = data->dev;
	struct regmap *regmap = data->regmap;

	ret = regmap_read(regmap, BMI270_CHIP_ID_REG, &chip_id);
	if (ret)
		return dev_err_probe(dev, ret, "Failed to read chip id");

....
	if (chip_id != data->chip_info->chip_id)
		dev_info(dev, "Unexpected chip id 0x%x", chip_id);

	if (chip_id == bmi260_chip_info.chip_id)
		data->chip_info = &bmi260_chip_info;
	else if (chip_id == bmi270_chip_info.chip_id)
		data->chip_info = &bmi270_chip_info;

	return 0;
}

The chip_info will be correct due the caller matching DT or ACPI before, and here,
driver is only double-checking the value at hardware and printing if it is not matching.
Printing as info can be confusing, since this is more like a warning than info. 
I don't have the hw here to test it, but I'm suggesting to just change the level
of that msg.
Tks and regards.

[1] https://github.com/torvalds/linux/blob/2d1373e4246da3b58e1df058374ed6b101804e07/drivers/iio/imu/bmi270/bmi270_core.c#L1599
[2] https://github.com/torvalds/linux/blob/2d1373e4246da3b58e1df058374ed6b101804e07/drivers/iio/imu/bmi270/bmi270_spi.c#L65
[3] https://github.com/torvalds/linux/blob/2d1373e4246da3b58e1df058374ed6b101804e07/drivers/iio/imu/bmi270/bmi270_i2c.c#L32
---
 drivers/iio/imu/bmi270/bmi270_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/bmi270_core.c
index 2ad230788532..a2f90ac22873 100644
--- a/drivers/iio/imu/bmi270/bmi270_core.c
+++ b/drivers/iio/imu/bmi270/bmi270_core.c
@@ -1473,7 +1473,7 @@ static int bmi270_validate_chip_id(struct bmi270_data *data)
 		return -ENODEV;
 
 	if (chip_id != data->chip_info->chip_id)
-		dev_info(dev, "Unexpected chip id 0x%x", chip_id);
+		dev_warn(dev, "Unexpected chip id 0x%x", chip_id);
 
 	if (chip_id == bmi260_chip_info.chip_id)
 		data->chip_info = &bmi260_chip_info;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-17 20:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-16 23:11 [PATCH] iio: imu: bmi270: use dev_warn for unexpected chip id Rodrigo Gobbi
2026-03-17  7:14 ` Andy Shevchenko
2026-03-17 20:47 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox