Skip to contentSkip to conversation

iio: imu: bmi270: Add spi driver for bmi270 imu

PATCH In review Alex Lanzano 2 participants 2 messages Oct 2, 2024 – Oct 10, 2024

Subsystems (2)
lore
Share & tools
lore

Alex Lanzano

author maintainer
#0 lore raw

PATCH v2 1/1 iio: imu: bmi270: Add spi driver for bmi270 imu

Implement SPI driver for the Bosch BMI270 6-axis IMU. Provide raw read write access to acceleration and angle velocity measurements via the SPI interface on the device.

---

Changes in v2:
- Remove unnecessary __le16 sample variable out of priv data
- Add static to regmap_config structures
- Sort includes in bmi270_spi.c alphabetically
- Rename "context" argument for spi regmap functions to "spi" and use it directly
- Replace spi_write with spi_write_then_read to ensure bounce buffer is always used

---
 drivers/iio/imu/bmi270/Kconfig       | 12 ++++
 drivers/iio/imu/bmi270/Makefile      |  1 +
 drivers/iio/imu/bmi270/bmi270.h      |  1 +
 drivers/iio/imu/bmi270/bmi270_core.c | 10 +---
 drivers/iio/imu/bmi270/bmi270_i2c.c  |  7 ++-
 drivers/iio/imu/bmi270/bmi270_spi.c  | 86 ++++++++++++++++++++++++++++
 6 files changed, 109 insertions(+), 8 deletions(-)
 create mode 100644 drivers/iio/imu/bmi270/bmi270_spi.c
drivers/iio/imu/bmi270/Kconfig +12 -0
index a8db44187286..0ffd29794fda 100644
@@ -18,3 +18,15 @@ config BMI270_I2C
 
 	  This driver can also be built as a module. If so, the module will be
 	  called bmi270_i2c.
+
+config BMI270_SPI
+	tristate "Bosch BMI270 SPI driver"
+	depends on SPI
+	select BMI270
+	select REGMAP_SPI
+	help
+	  Enable support for the Bosch BMI270 6-Axis IMU connected to SPI
+	  interface.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called bmi270_spi.
drivers/iio/imu/bmi270/Makefile +1 -0
index ab4acaaee6d2..d96c96fc3d83 100644
@@ -4,3 +4,4 @@
 #
 obj-$(CONFIG_BMI270) += bmi270_core.o
 obj-$(CONFIG_BMI270_I2C) += bmi270_i2c.o
+obj-$(CONFIG_BMI270_SPI) += bmi270_spi.o
drivers/iio/imu/bmi270/bmi270.h +1 -0
index 608b29ea58a3..8ac20ad7ee94 100644
@@ -4,6 +4,7 @@
 #define BMI270_H_
 
 #include <linux/regmap.h>
+#include <linux/iio/iio.h>
 
 struct device;
 struct bmi270_data {
drivers/iio/imu/bmi270/bmi270_core.c +3 -7
index 8e45343d6472..638ce2c30d0e 100644
@@ -66,12 +66,6 @@ enum bmi270_scan {
 	BMI270_SCAN_GYRO_Z,
 };
 
-const struct regmap_config bmi270_regmap_config = {
-	.reg_bits = 8,
-	.val_bits = 8,
-};
-EXPORT_SYMBOL_NS_GPL(bmi270_regmap_config, IIO_BMI270);
-
 static int bmi270_get_data(struct bmi270_data *bmi270_device,
 			   int chan_type, int axis, int *val)
 {
@@ -90,7 +84,9 @@ static int bmi270_get_data(struct bmi270_data *bmi270_device,
 		return -EINVAL;
 	}
 
-	ret = regmap_bulk_read(bmi270_device->regmap, reg, &sample, sizeof(sample));
+	ret = regmap_bulk_read(bmi270_device->regmap, reg,
+			       &sample,
+			       sizeof(sample));
 	if (ret)
 		return ret;
 
drivers/iio/imu/bmi270/bmi270_i2c.c +6 -1
index f70dee2d8a64..e9025d22d5cc 100644
@@ -9,12 +9,17 @@
 
 #include "bmi270.h"
 
+static const struct regmap_config bmi270_i2c_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+};
+
 static int bmi270_i2c_probe(struct i2c_client *client)
 {
 	struct regmap *regmap;
 	struct device *dev = &client->dev;
 
-	regmap = devm_regmap_init_i2c(client, &bmi270_regmap_config);
+	regmap = devm_regmap_init_i2c(client, &bmi270_i2c_regmap_config);
 	if (IS_ERR(regmap))
 		return dev_err_probe(dev, PTR_ERR(regmap),
 				     "Failed to init i2c regmap");
drivers/iio/imu/bmi270/bmi270_spi.c new file +86 -0

86 lines not on this page · raw message

Signature · 1 line
2.46.2
maintainer
#1 lore raw
Quoted 5 lines · On Tue, 1 Oct 2024 23:36:22 -0400 Alex Lanzano <[email protected]> wrote:

Implement SPI driver for the Bosch BMI270 6-axis IMU. Provide raw read write access to acceleration and angle velocity measurements via the SPI interface on the device.

Hi Alex,

Applied with one minor tweak. See below.

Applied to the togreg branch of iio.git and pushed out as testing for 0-day to poke at it and see if we missed anything.

Thanks,

Jonathan

p.s. Thought I'd sent this already - hence I actually applied this last weekend :(

Quoted 19 lines

struct bmi270_data {

drivers/iio/imu/bmi270/bmi270_core.c +0 -6
index 8e45343d6472..638ce2c30d0e 100644
@@ -66,12 +66,6 @@ enum bmi270_scan {
 	BMI270_SCAN_GYRO_Z,
 };
 
-const struct regmap_config bmi270_regmap_config = {
-	.reg_bits = 8,
-	.val_bits = 8,
-};
-EXPORT_SYMBOL_NS_GPL(bmi270_regmap_config, IIO_BMI270);
-
 static int bmi270_get_data(struct bmi270_data *bmi270_device,
 			   int chan_type, int axis, int *val)
 {

drivers/iio/imu/bmi270/bmi270_core.c static int bmi270_get_data(struct bmi270_data *bmi270_device, · line 89

Quoted 7 lines
drivers/iio/imu/bmi270/bmi270_core.c +3 -1
@@ -90,7 +84,9 @@ static int bmi270_get_data(struct bmi270_data *bmi270_device,
 		return -EINVAL;
 	}
 
-	ret = regmap_bulk_read(bmi270_device->regmap, reg, &sample, sizeof(sample));
+	ret = regmap_bulk_read(bmi270_device->regmap, reg,
+			       &sample,
+			       sizeof(sample));

Trivial but this is an unrelated change. Possibly valid but doesn't belong in this patch set. I'll drop it whilst applying.

Quoted 3 lines
drivers/iio/imu/bmi270/bmi270_core.c +0 -0
 	if (ret)
 		return ret;