Skip to contentSkip to conversation

iio: accel: Add support for the Bosch-Sensortec BMI088

PATCH In review Mike Looijmans 2 participants 6 messages Mar 23, 2020 – Mar 24, 2020 IIO

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 iio: accel: Add support for the Bosch-Sensortec BMI088

The BMI088 is a combined module with both accelerometer and gyroscope. This adds the accelerometer driver support for the SPI interface. The gyroscope part is already supported by the BMG160 driver.

---
v2: Remove unused typedefs and variables
Fix error return when iio_device_register fails
v3: Processed comments from Jonathan Cameron and Lars-Peter Clausen
implement runtime PM (tested by code tracing) and sleep fix scale and offset factors for accel and temperature and return raw values instead of pre-scaled ones
Use iio_device_{claim,release}_direct_mode
Remove unused code and structs
Use a cache-aligned buffer for bulk read
Configure and enable caching register values
v4: Remove unused #include directives
Remove unused #defines for event and irq
Replace (ret < 0) with (ret) for all regmap calls Consistent checking of IO errors in probe and init Removed #ifdef CONFIG_PM guard
Use bitops for set_frequency instead of loop with shift s/__s16/s16/g
Remove excess blank lines
Don't return -EAGAIN in pm_runtime

 drivers/iio/accel/Kconfig             |  17 +
 drivers/iio/accel/Makefile            |   2 +
 drivers/iio/accel/bmi088-accel-core.c | 632 ++++++++++++++++++++++++++
 drivers/iio/accel/bmi088-accel-spi.c  |  85 ++++
 drivers/iio/accel/bmi088-accel.h      |  12 +
 5 files changed, 748 insertions(+)
 create mode 100644 drivers/iio/accel/bmi088-accel-core.c
 create mode 100644 drivers/iio/accel/bmi088-accel-spi.c
 create mode 100644 drivers/iio/accel/bmi088-accel.h
drivers/iio/accel/Kconfig +17 -0
index 5d91a6dda894..7ed9c82b731b 100644
@@ -151,6 +151,23 @@ config BMC150_ACCEL_SPI
 	tristate
 	select REGMAP_SPI
 
+config BMI088_ACCEL
+	tristate "Bosch BMI088 Accelerometer Driver"
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	select REGMAP
+	select BMI088_ACCEL_SPI
+	help
+	  Say yes here to build support for the Bosch BMI088 accelerometer.
+
+	  This is a combo module with both accelerometer and gyroscope.
+	  This driver is only implementing accelerometer part, which has
+	  its own address and register map.
+
+config BMI088_ACCEL_SPI
+	tristate
+	select REGMAP_SPI
+
 config DA280
 	tristate "MiraMEMS DA280 3-axis 14-bit digital accelerometer driver"
 	depends on I2C
drivers/iio/accel/Makefile +2 -0
index 3a051cf37f40..f44613103ae5 100644
@@ -19,6 +19,8 @@ obj-$(CONFIG_BMA400_I2C) += bma400_i2c.o
 obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o
 obj-$(CONFIG_BMC150_ACCEL_I2C) += bmc150-accel-i2c.o
 obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o
+obj-$(CONFIG_BMI088_ACCEL) += bmi088-accel-core.o
+obj-$(CONFIG_BMI088_ACCEL_SPI) += bmi088-accel-spi.o
 obj-$(CONFIG_DA280)	+= da280.o
 obj-$(CONFIG_DA311)	+= da311.o
 obj-$(CONFIG_DMARD06)	+= dmard06.o
drivers/iio/accel/bmi088-accel-core.c new file +632 -0

632 lines not on this page · raw message

drivers/iio/accel/bmi088-accel-spi.c new file +85 -0

85 lines not on this page · raw message

drivers/iio/accel/bmi088-accel.h new file +12 -0
new file mode 100644
index 000000000000..fce6427bb7b8
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef BMI088_ACCEL_H
+#define BMI088_ACCEL_H
+
+extern const struct regmap_config bmi088_regmap_conf;
+extern const struct dev_pm_ops bmi088_accel_pm_ops;
+
+int bmi088_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
+			    const char *name, bool block_supported);
+int bmi088_accel_core_remove(struct device *dev);
+
+#endif /* BMI088_ACCEL_H */
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines · Mike Looijmans

The BMI088 is a combined module with both accelerometer and gyroscope. This adds the accelerometer driver support for the SPI interface. The gyroscope part is already supported by the BMG160 driver.

Thank you, the comment about shared buffer given to v3 still applies. Also see below.

...

drivers/iio/accel/bmi088-accel-core.c line 78

Quoted 6 lines
drivers/iio/accel/bmi088-accel-core.c new file +5 -0
+enum bmi088_accel_axis {
+	AXIS_X,
+	AXIS_Y,
+	AXIS_Z,
 
+	AXIS_MAX,

If it's a terminator entry, comma is not needed.

Quoted 1 line

+};

...

drivers/iio/accel/bmi088-accel-core.c line 103

Quoted 11 lines
drivers/iio/accel/bmi088-accel-core.c new file +11 -0
+/* Available ODR (output data rates) in Hz */
+enum bmi088_odr_modes {
+	BMI088_ACCEL_MODE_ODR_12_5 = 0x5,
+	BMI088_ACCEL_MODE_ODR_25 = 0x6,
+	BMI088_ACCEL_MODE_ODR_50 = 0x7,
+	BMI088_ACCEL_MODE_ODR_100 = 0x8,
+	BMI088_ACCEL_MODE_ODR_200 = 0x9,
+	BMI088_ACCEL_MODE_ODR_400 = 0xa,
+	BMI088_ACCEL_MODE_ODR_800 = 0xb,
+	BMI088_ACCEL_MODE_ODR_1600 = 0xc,
+};

I'm wondering if you need this enum at all? Only 3 out of 8 are in use, and 25 of them can be still derived from the 12.5 one.

Maybe replace with comment and ranges?

(But it's up to you, I have no strong opinion here)

...

drivers/iio/accel/bmi088-accel-core.c line 151

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +7 -0
+static int bmi088_accel_set_power_state(struct bmi088_accel_data *data, bool on)
+{
+	struct device *dev = regmap_get_device(data->regmap);
+	int ret;
+
+	if (on) {
+		ret = pm_runtime_get_sync(dev);
		if (ret < 0)
			pm_runtime_put_noidle(dev);

See below.

drivers/iio/accel/bmi088-accel-core.c line 160

Quoted 10 lines
drivers/iio/accel/bmi088-accel-core.c new file +9 -0
+	} else {
+		pm_runtime_mark_last_busy(dev);
+		ret = pm_runtime_put_autosuspend(dev);
+	}
+
+	if (ret < 0) {
+		dev_err(dev, "Failed: %s(%d)\n", __func__, on);
 
+		if (on)
+			pm_runtime_put_noidle(dev);

Perhaps refactor as above?

In this case it maybe simple...

drivers/iio/accel/bmi088-accel-core.c line 165

Quoted 5 lines
drivers/iio/accel/bmi088-accel-core.c new file +5 -0
+
+		return ret;
+	}
+
+	return 0;

...like this

	if (ret < 0)
		dev_err(dev, "Failed: %s(%d)\n", __func__, on);

	return ret < 0 ? ret : 0;

(I guess compiler is clever enough to avoid condition twice, but again, I have
no strong opinion)

Quoted 1 line

+}

...

drivers/iio/accel/bmi088-accel-core.c line 174

Quoted 8 lines
drivers/iio/accel/bmi088-accel-core.c new file +7 -0
+static int bmi088_accel_enable(struct bmi088_accel_data *data, bool on_off)
+{
+	struct device *dev = regmap_get_device(data->regmap);
+	int ret;
+
 
+	ret = regmap_write(data->regmap, BMI088_ACCEL_REG_PWR_CTRL,
+			   on_off ? 0x4 : 0x0);

I think

	u32 val = on_off ? 0x4 : 0x0;
	...
	ret = regmap_write(data->regmap, BMI088_ACCEL_REG_PWR_CTRL, val);

will look better.

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +6 -0
+	if (ret) {
+		dev_err(dev, "Error writing ACC_PWR_CTRL reg\n");
+		return ret;
+	}
 
+	return 0;
+}

drivers/iio/accel/bmi088-accel-core.c line 193

Quoted 10 lines
drivers/iio/accel/bmi088-accel-core.c new file +10 -0
+
+/* In suspend mode, only the accelerometer is powered down. */
+static int bmi088_accel_set_mode(struct bmi088_accel_data *data,
+				enum bmi088_power_modes mode)
+{
+	struct device *dev = regmap_get_device(data->regmap);
+	int ret;
+
+	ret = regmap_write(data->regmap, BMI088_ACCEL_REG_PWR_CONF,
+			   mode == BMI088_ACCEL_MODE_SUSPEND ? 0x3 : 0x0);

Ditto.

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +7 -0
+	if (ret) {
+		dev_err(dev, "Error writing ACCEL_PWR_CONF reg\n");
+		return ret;
+	}
+
+	return 0;
+}

...

drivers/iio/accel/bmi088-accel-core.c line 208

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +7 -0
+static int bmi088_accel_set_bw(struct bmi088_accel_data *data,
+				enum bmi088_odr_modes odr_mode,
+				enum bmi088_osr_modes osr_mode)
+{
+	struct device *dev = regmap_get_device(data->regmap);
+	int ret;
+	u8 value = (osr_mode << 4) | (odr_mode & 0xF);

_MASK (GENMASK() + _SHIFT? (See also below)

	u8 value = (osr_mode << _SHIFT) | (odr_mode & _MASK);
	int ret;

(note reverse xmas tree ordering)

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +7 -0
+
+	ret = regmap_write(data->regmap, BMI088_ACCEL_REG_ACC_CONF, value);
+	if (ret) {
+		dev_err(dev, "Error writing ACCEL_PWR_CONF reg\n");
+		return ret;
+	}
+

drivers/iio/accel/bmi088-accel-core.c line 230

Quoted 10 lines
drivers/iio/accel/bmi088-accel-core.c new file +9 -0
+	return 0;
+}
+
+static int bmi088_accel_get_sample_freq(struct bmi088_accel_data *data,
+					int* val, int *val2)
+{
+	unsigned int value;
+	int ret;
 
+	value &= 0xf; /* ODR in lower 4 bits */

_MASK? See above.

Quoted 12 lines
drivers/iio/accel/bmi088-accel-core.c new file +12 -0
+	if (value == BMI088_ACCEL_MODE_ODR_12_5) {
+		*val = 12;
+		*val2 = 500000;
+		ret = IIO_VAL_INT_PLUS_MICRO;
+	} else {
+		*val = 25 << (value - BMI088_ACCEL_MODE_ODR_25);
+		*val2 = 0;
+		ret = IIO_VAL_INT;
+	}
+
+	return ret;
+}

...

drivers/iio/accel/bmi088-accel-core.c line 251

Quoted 10 lines
drivers/iio/accel/bmi088-accel-core.c new file +9 -0
+
+static int bmi088_accel_set_sample_freq(struct bmi088_accel_data *data, int val)
+{
+	unsigned int value = BMI088_ACCEL_MODE_ODR_1600;
+
+	if (val < 12 || val > 1600)
+		return -EINVAL;
+
 
+	value = fls(val) + (BMI088_ACCEL_MODE_ODR_12_5 - 4);

Wouldn't be

	value = fls(val) + 1;

more obvious? Or, perhaps,

roundup_pow_of_two()

?

drivers/iio/accel/bmi088-accel-core.c line 254

Quoted 2 lines
drivers/iio/accel/bmi088-accel-core.c new file +2 -0
+	return regmap_update_bits(data->regmap, BMI088_ACCEL_REG_ACC_CONF,
+				  0x0f, value);

_MASK ?

drivers/iio/accel/bmi088-accel-core.c line 273

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +5 -0
+}
 
+	if (ret)
+		return ret;
+
 
+	*val = temp >> 5;

Magic shift.

...

drivers/iio/accel/bmi088-accel-core.c line 294

Quoted 6 lines
drivers/iio/accel/bmi088-accel-core.c new file +5 -0
+	s16 raw_val;
 
+	ret = regmap_bulk_read(data->regmap,
+			       BMI088_ACCEL_AXIS_TO_REG(chan->scan_index),
+			       data->buffer, 2);
+	raw_val = get_unaligned_le16(data->buffer);

I'm wondering if you can simple use le16_to_cpu()? I guess that buffer is always aligned and since you access it always by even addresses, it implies aligned access. Applies to other places as well.

...

drivers/iio/accel/bmi088-accel-core.c line 351

Quoted 3 lines
drivers/iio/accel/bmi088-accel-core.c new file +2 -0
+		case IIO_ACCEL:
 
+		{

Why do you need block?

drivers/iio/accel/bmi088-accel-core.c line 357

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +6 -0
+			ret = regmap_read(data->regmap,
+					  BMI088_ACCEL_REG_ACC_RANGE, val);
+			if (ret)
+				return ret;
+
 
+			*val2 =  15 - (*val & 0x3);

Extra spaces.

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +7 -0
+			*val = 3 * 980;
+
+			return IIO_VAL_FRACTIONAL_LOG2;
+		}
+		default:
+			return -EINVAL;
+		}

...

drivers/iio/accel/bmi088-accel-core.c line 445

Quoted 3 lines
drivers/iio/accel/bmi088-accel-core.c new file +3 -0
+static const unsigned long bmi088_accel_scan_masks[] = {
+	BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z),
+	0

+ comma or is it agreed value for termination the list?

Quoted 1 line

+};

...

drivers/iio/accel/bmi088-accel-core.c line 618

Quoted 2 lines
drivers/iio/accel/bmi088-accel-core.c new file +2 -0
+	usleep_range(BMI088_ACCEL_MAX_STARTUP_TIME_MS * 1000,
+		BMI088_ACCEL_MAX_STARTUP_TIME_MS * 1000 * 2);
	unsigned long /* or what is used */ sleep = BMI088_ACCEL_MAX_STARTUP_TIME_MS * USEC_PER_MSEC;
	...
	usleep_range(sleep, 2 * sleep);

?

...

drivers/iio/accel/bmi088-accel-spi.c line 31

Quoted 1 line
drivers/iio/accel/bmi088-accel-spi.c new file +1 -0
+	addr[0] |= 0x80; /* bit7 = RW = '1' */

BIT(7) ?

...

drivers/iio/accel/bmi088-accel-spi.c line 67

Quoted 3 lines
drivers/iio/accel/bmi088-accel-spi.c new file +2 -0
+static const struct spi_device_id bmi088_accel_id[] = {
 
+	{"bmi088_accel", 0},

', 0' part is not needed.

drivers/iio/accel/bmi088-accel.h line 6

Quoted 13 lines
drivers/iio/accel/bmi088-accel.h new file +9 -0
+	{}
+};
 
 
 
+++ b/drivers/iio/accel/bmi088-accel.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef BMI088_ACCEL_H
+#define BMI088_ACCEL_H
+
+extern const struct regmap_config bmi088_regmap_conf;
+extern const struct dev_pm_ops bmi088_accel_pm_ops;

Do you need extern?

drivers/iio/accel/bmi088-accel.h line 10

Quoted 3 lines
drivers/iio/accel/bmi088-accel.h new file +3 -0
+int bmi088_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
+			    const char *name, bool block_supported);
+int bmi088_accel_core_remove(struct device *dev);

This needs

#include <linux/types.h>

struct device;
struct regmap;

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 11 lines · Andy Shevchenko
Quoted 3 lines · Mike Looijmans

The BMI088 is a combined module with both accelerometer and gyroscope. This adds the accelerometer driver support for the SPI interface. The gyroscope part is already supported by the BMG160 driver.

Thank you, the comment about shared buffer given to v3 still applies. Also see below.

...

Quoted 8 lines

drivers/iio/accel/bmi088-accel-core.c line 78

Quoted 6 lines
drivers/iio/accel/bmi088-accel-core.c new file +5 -0
+enum bmi088_accel_axis {
+	AXIS_X,
+	AXIS_Y,
+	AXIS_Z,
 
+	AXIS_MAX,

If it's a terminator entry, comma is not needed.

Actually it isn't used at all, I'll remove it.

Quoted 20 lines
Quoted 2 lines

+};

...

drivers/iio/accel/bmi088-accel-core.c line 103

Quoted 11 lines
drivers/iio/accel/bmi088-accel-core.c new file +11 -0
+/* Available ODR (output data rates) in Hz */
+enum bmi088_odr_modes {
+	BMI088_ACCEL_MODE_ODR_12_5 = 0x5,
+	BMI088_ACCEL_MODE_ODR_25 = 0x6,
+	BMI088_ACCEL_MODE_ODR_50 = 0x7,
+	BMI088_ACCEL_MODE_ODR_100 = 0x8,
+	BMI088_ACCEL_MODE_ODR_200 = 0x9,
+	BMI088_ACCEL_MODE_ODR_400 = 0xa,
+	BMI088_ACCEL_MODE_ODR_800 = 0xb,
+	BMI088_ACCEL_MODE_ODR_1600 = 0xc,
+};

I'm wondering if you need this enum at all? Only 3 out of 8 are in use, and 25 of them can be still derived from the 12.5 one.

Quoted 3 lines

Maybe replace with comment and ranges?

(But it's up to you, I have no strong opinion here)

Comment and ranges sounds better, it's all power-of-two stuff, and the values aren't actually being used.

Quoted 39 lines

...

drivers/iio/accel/bmi088-accel-core.c line 151

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +7 -0
+static int bmi088_accel_set_power_state(struct bmi088_accel_data *data, bool on)
+{
+	struct device *dev = regmap_get_device(data->regmap);
+	int ret;
+
+	if (on) {
+		ret = pm_runtime_get_sync(dev);
		if (ret < 0)
			pm_runtime_put_noidle(dev);

See below.

drivers/iio/accel/bmi088-accel-core.c line 160

Quoted 10 lines
drivers/iio/accel/bmi088-accel-core.c new file +9 -0
+	} else {
+		pm_runtime_mark_last_busy(dev);
+		ret = pm_runtime_put_autosuspend(dev);
+	}
+
+	if (ret < 0) {
+		dev_err(dev, "Failed: %s(%d)\n", __func__, on);
 
+		if (on)
+			pm_runtime_put_noidle(dev);

Perhaps refactor as above?

In this case it maybe simple...

drivers/iio/accel/bmi088-accel-core.c line 165

Quoted 5 lines
drivers/iio/accel/bmi088-accel-core.c new file +5 -0
+
+		return ret;
+	}
+
+	return 0;

...like this

Quoted 7 lines
	if (ret < 0)
		dev_err(dev, "Failed: %s(%d)\n", __func__, on);

	return ret < 0 ? ret : 0;

(I guess compiler is clever enough to avoid condition twice, but again, I have
no strong opinion)

As most of the method body depends on that "bool" argument, I would actually just split it into separate "enable" and "disable" methods. Simpler to read and understand, and probably doesn't make a difference in compiled size either.

Quoted 16 lines
Quoted 2 lines

+}

...

drivers/iio/accel/bmi088-accel-core.c line 174

Quoted 8 lines
drivers/iio/accel/bmi088-accel-core.c new file +7 -0
+static int bmi088_accel_enable(struct bmi088_accel_data *data, bool on_off)
+{
+	struct device *dev = regmap_get_device(data->regmap);
+	int ret;
+
 
+	ret = regmap_write(data->regmap, BMI088_ACCEL_REG_PWR_CTRL,
+			   on_off ? 0x4 : 0x0);

I think

Quoted 6 lines
	u32 val = on_off ? 0x4 : 0x0;
	...
	ret = regmap_write(data->regmap, BMI088_ACCEL_REG_PWR_CTRL, val);

will look better.

Agree

Quoted 198 lines
Quoted 8 lines
drivers/iio/accel/bmi088-accel-core.c new file +6 -0
+	if (ret) {
+		dev_err(dev, "Error writing ACC_PWR_CTRL reg\n");
+		return ret;
+	}
 
+	return 0;
+}

drivers/iio/accel/bmi088-accel-core.c line 193

Quoted 10 lines
drivers/iio/accel/bmi088-accel-core.c new file +10 -0
+
+/* In suspend mode, only the accelerometer is powered down. */
+static int bmi088_accel_set_mode(struct bmi088_accel_data *data,
+				enum bmi088_power_modes mode)
+{
+	struct device *dev = regmap_get_device(data->regmap);
+	int ret;
+
+	ret = regmap_write(data->regmap, BMI088_ACCEL_REG_PWR_CONF,
+			   mode == BMI088_ACCEL_MODE_SUSPEND ? 0x3 : 0x0);

Ditto.

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +7 -0
+	if (ret) {
+		dev_err(dev, "Error writing ACCEL_PWR_CONF reg\n");
+		return ret;
+	}
+
+	return 0;
+}

...

drivers/iio/accel/bmi088-accel-core.c line 208

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +7 -0
+static int bmi088_accel_set_bw(struct bmi088_accel_data *data,
+				enum bmi088_odr_modes odr_mode,
+				enum bmi088_osr_modes osr_mode)
+{
+	struct device *dev = regmap_get_device(data->regmap);
+	int ret;
+	u8 value = (osr_mode << 4) | (odr_mode & 0xF);

_MASK (GENMASK() + _SHIFT? (See also below)

	u8 value = (osr_mode << _SHIFT) | (odr_mode & _MASK);
	int ret;

(note reverse xmas tree ordering)

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +7 -0
+
+	ret = regmap_write(data->regmap, BMI088_ACCEL_REG_ACC_CONF, value);
+	if (ret) {
+		dev_err(dev, "Error writing ACCEL_PWR_CONF reg\n");
+		return ret;
+	}
+

drivers/iio/accel/bmi088-accel-core.c line 230

Quoted 10 lines
drivers/iio/accel/bmi088-accel-core.c new file +9 -0
+	return 0;
+}
+
+static int bmi088_accel_get_sample_freq(struct bmi088_accel_data *data,
+					int* val, int *val2)
+{
+	unsigned int value;
+	int ret;
 
+	value &= 0xf; /* ODR in lower 4 bits */

_MASK? See above.

Quoted 12 lines
drivers/iio/accel/bmi088-accel-core.c new file +12 -0
+	if (value == BMI088_ACCEL_MODE_ODR_12_5) {
+		*val = 12;
+		*val2 = 500000;
+		ret = IIO_VAL_INT_PLUS_MICRO;
+	} else {
+		*val = 25 << (value - BMI088_ACCEL_MODE_ODR_25);
+		*val2 = 0;
+		ret = IIO_VAL_INT;
+	}
+
+	return ret;
+}

...

drivers/iio/accel/bmi088-accel-core.c line 251

Quoted 10 lines
drivers/iio/accel/bmi088-accel-core.c new file +9 -0
+
+static int bmi088_accel_set_sample_freq(struct bmi088_accel_data *data, int val)
+{
+	unsigned int value = BMI088_ACCEL_MODE_ODR_1600;
+
+	if (val < 12 || val > 1600)
+		return -EINVAL;
+
 
+	value = fls(val) + (BMI088_ACCEL_MODE_ODR_12_5 - 4);

Wouldn't be

	value = fls(val) + 1;

more obvious? Or, perhaps,

roundup_pow_of_two()

?

drivers/iio/accel/bmi088-accel-core.c line 254

Quoted 2 lines
drivers/iio/accel/bmi088-accel-core.c new file +2 -0
+	return regmap_update_bits(data->regmap, BMI088_ACCEL_REG_ACC_CONF,
+				  0x0f, value);

_MASK ?

drivers/iio/accel/bmi088-accel-core.c line 273

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +5 -0
+}
 
+	if (ret)
+		return ret;
+
 
+	*val = temp >> 5;

Magic shift.

...

drivers/iio/accel/bmi088-accel-core.c line 294

Quoted 6 lines
drivers/iio/accel/bmi088-accel-core.c new file +5 -0
+	s16 raw_val;
 
+	ret = regmap_bulk_read(data->regmap,
+			       BMI088_ACCEL_AXIS_TO_REG(chan->scan_index),
+			       data->buffer, 2);
+	raw_val = get_unaligned_le16(data->buffer);

I'm wondering if you can simple use le16_to_cpu()? I guess that buffer is always aligned and since you access it always by even addresses, it implies aligned access. Applies to other places as well.

...

drivers/iio/accel/bmi088-accel-core.c line 351

Quoted 3 lines
drivers/iio/accel/bmi088-accel-core.c new file +2 -0
+		case IIO_ACCEL:
 
+		{

Why do you need block?

drivers/iio/accel/bmi088-accel-core.c line 357

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +6 -0
+			ret = regmap_read(data->regmap,
+					  BMI088_ACCEL_REG_ACC_RANGE, val);
+			if (ret)
+				return ret;
+
 
+			*val2 =  15 - (*val & 0x3);

Extra spaces.

Quoted 7 lines
drivers/iio/accel/bmi088-accel-core.c new file +7 -0
+			*val = 3 * 980;
+
+			return IIO_VAL_FRACTIONAL_LOG2;
+		}
+		default:
+			return -EINVAL;
+		}

...

drivers/iio/accel/bmi088-accel-core.c line 445

Quoted 3 lines
drivers/iio/accel/bmi088-accel-core.c new file +3 -0
+static const unsigned long bmi088_accel_scan_masks[] = {
+	BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z),
+	0

+ comma or is it agreed value for termination the list?

Quoted 1 line

+};

...

drivers/iio/accel/bmi088-accel-core.c line 618

Quoted 2 lines
drivers/iio/accel/bmi088-accel-core.c new file +2 -0
+	usleep_range(BMI088_ACCEL_MAX_STARTUP_TIME_MS * 1000,
+		BMI088_ACCEL_MAX_STARTUP_TIME_MS * 1000 * 2);
	unsigned long /* or what is used */ sleep = BMI088_ACCEL_MAX_STARTUP_TIME_MS * USEC_PER_MSEC;
	...
	usleep_range(sleep, 2 * sleep);

?

...

drivers/iio/accel/bmi088-accel-spi.c line 31

Quoted 1 line
drivers/iio/accel/bmi088-accel-spi.c new file +1 -0
+	addr[0] |= 0x80; /* bit7 = RW = '1' */

BIT(7) ?

...

drivers/iio/accel/bmi088-accel-spi.c line 67

Quoted 3 lines
drivers/iio/accel/bmi088-accel-spi.c new file +2 -0
+static const struct spi_device_id bmi088_accel_id[] = {
 
+	{"bmi088_accel", 0},

', 0' part is not needed.

Quoted 2 lines
(quoted diff) +2 -0
+	{}
+};
Quoted 10 lines

drivers/iio/accel/bmi088-accel.h line 6

Quoted 8 lines

+++ b/drivers/iio/accel/bmi088-accel.h

drivers/iio/accel/bmi088-accel.h new file +6 -0
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef BMI088_ACCEL_H
+#define BMI088_ACCEL_H
+
+extern const struct regmap_config bmi088_regmap_conf;
+extern const struct dev_pm_ops bmi088_accel_pm_ops;

Do you need extern?

probably not.

Quoted 7 lines

drivers/iio/accel/bmi088-accel.h line 10

Quoted 4 lines
drivers/iio/accel/bmi088-accel.h new file +3 -0
+int bmi088_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
+			    const char *name, bool block_supported);
+int bmi088_accel_core_remove(struct device *dev);

This needs

Quoted 5 lines

#include <linux/types.h>

struct device;
struct regmap;

Hmm, and "struct regmap_config" as well I guess (see above)

Signature · 1 line
Mike Looijmans
#3 lore raw
Quoted 9 lines · Mike Looijmans
Quoted 8 lines · Andy Shevchenko
Quoted 3 lines · Mike Looijmans

The BMI088 is a combined module with both accelerometer and gyroscope. This adds the accelerometer driver support for the SPI interface. The gyroscope part is already supported by the BMG160 driver.

Thank you, the comment about shared buffer given to v3 still applies. Also see below.

Since you didn't comment on many, I assume you are in favor to follow. Please, comment if it's not the case.

...

Quoted 4 lines

As most of the method body depends on that "bool" argument, I would actually just split it into separate "enable" and "disable" methods. Simpler to read and understand, and probably doesn't make a difference in compiled size either.

It's even better!

...

Quoted 17 lines
Quoted 7 lines

drivers/iio/accel/bmi088-accel.h line 6

Quoted 5 lines
drivers/iio/accel/bmi088-accel.h new file +5 -0
+#ifndef BMI088_ACCEL_H
+#define BMI088_ACCEL_H
+
+extern const struct regmap_config bmi088_regmap_conf;
+extern const struct dev_pm_ops bmi088_accel_pm_ops;

Do you need extern?

probably not.

Quoted 7 lines

drivers/iio/accel/bmi088-accel.h line 10

Quoted 4 lines
drivers/iio/accel/bmi088-accel.h new file +3 -0
+int bmi088_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
+			    const char *name, bool block_supported);
+int bmi088_accel_core_remove(struct device *dev);

This needs

Quoted 7 lines
Quoted 5 lines

#include <linux/types.h>

struct device;
struct regmap;

Hmm, and "struct regmap_config" as well I guess (see above)

Oh, it requires headers then

So,

#include <linux/pm.h>
#include <linux/regmap.h>
#include <linux/types.h>

struct device;

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Mike Looijmans
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · Mike Looijmans

The BMI088 is a combined module with both accelerometer and gyroscope. This adds the accelerometer driver support for the SPI interface. The gyroscope part is already supported by the BMG160 driver.

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

Thank you, the comment about shared buffer given to v3 still applies. Also see below.

Since you didn't comment on many, I assume you are in favor to follow. Please, comment if it's not the case.

Didn't mention it explicitly, but no comment means "I agree".

Quoted 11 lines

...

Quoted 4 lines

As most of the method body depends on that "bool" argument, I would actually just split it into separate "enable" and "disable" methods. Simpler to read and understand, and probably doesn't make a difference in compiled size either.

It's even better!

...

Hmm, reading the datasheet again about the power modes is now confusing me. It's been awhile since I read that, and I don't think that I got it right....

there are two power setting registers, and it's not quite clear to me any more what I'm supposed to do with them...

I think the intention is that I just set ACC_PWR_CTRL to "4" after reset/probe, and leave it there, and use the ACC_PWR_CONF register to go in and out of suspend state. This affects the temperature sensor as well.

I'll need a bit of caffeine before I get to v5.

Quoted 36 lines
Quoted 18 lines
Quoted 8 lines

drivers/iio/accel/bmi088-accel.h line 6

Quoted 6 lines
drivers/iio/accel/bmi088-accel.h new file +5 -0
+#ifndef BMI088_ACCEL_H
+#define BMI088_ACCEL_H
+
+extern const struct regmap_config bmi088_regmap_conf;
+extern const struct dev_pm_ops bmi088_accel_pm_ops;

Do you need extern?

probably not.

Quoted 7 lines

drivers/iio/accel/bmi088-accel.h line 10

Quoted 4 lines
drivers/iio/accel/bmi088-accel.h new file +3 -0
+int bmi088_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
+			    const char *name, bool block_supported);
+int bmi088_accel_core_remove(struct device *dev);

This needs

Quoted 7 lines
Quoted 5 lines

#include <linux/types.h>

struct device;
struct regmap;

Hmm, and "struct regmap_config" as well I guess (see above)

Oh, it requires headers then

So,

#include <linux/pm.h>
#include <linux/regmap.h>
#include <linux/types.h>

struct device;

Signature · 1 line
Mike Looijmans
#5 lore raw
In reply to Andy Shevchenko
Quoted 16 lines · Andy Shevchenko
Quoted 9 lines · Mike Looijmans
Quoted 8 lines · Andy Shevchenko
Quoted 3 lines · Mike Looijmans

The BMI088 is a combined module with both accelerometer and gyroscope. This adds the accelerometer driver support for the SPI interface. The gyroscope part is already supported by the BMG160 driver.

Thank you, the comment about shared buffer given to v3 still applies. Also see below.

Since you didn't comment on many, I assume you are in favor to follow. Please, comment if it's not the case.

...

Quoted 18 lines
Quoted 4 lines

As most of the method body depends on that "bool" argument, I would actually just split it into separate "enable" and "disable" methods. Simpler to read and understand, and probably doesn't make a difference in compiled size either.

It's even better!

...

Quoted 9 lines
Quoted 7 lines

drivers/iio/accel/bmi088-accel.h line 6

Quoted 5 lines
drivers/iio/accel/bmi088-accel.h new file +5 -0
+#ifndef BMI088_ACCEL_H
+#define BMI088_ACCEL_H
+
+extern const struct regmap_config bmi088_regmap_conf;
+extern const struct dev_pm_ops bmi088_accel_pm_ops;

Do you need extern?

probably not.

Apparently I do, without "extern" the compiler will complain:
multiple definition of `bmi088_accel_pm_ops'

with variable declarations the "extern" keyword is needed.