Skip to contentSkip to conversation

iio: accel: bma220 improvements

PATCH Applied Petre Rodan 2 participants 42 messages Oct 5, 2025 – Oct 14, 2025

Subsystems (2)
lore
Share & tools
lore

Petre Rodan

author maintainer
#0 lore raw

v4 cover iio: accel: bma220 improvements

Series of patches that switch the driver to the regmap API and add i2c connectivity.

Tested in I2C and SPI modes with two different sensors.

Event-related code was skipped since the patch series was getting too large.

Bindings have been merged into testing branch, but this series is still based on 'togreg'.

Contains fixes based on feedback from Krzysztof, David, Jonathan and Andy.

---
Changes in v4:
- fixes based on Andy's feedback
- patch reordering (Andy)
- Link to v3: https://lore.kernel.org/r/20250913-b4-bma220_improvements-v3-0-0b97279b4e45@subdimension.ro

---
Petre Rodan (19):
iio: accel: bma220: remove incorrect kernel-doc marking
iio: accel: bma220: relax constraints during probe()
iio: accel: bma220: cleanup license string
iio: accel: bma220: shorten spi->dev calls
iio: accel: bma220: move bma220_power function
iio: accel: bma220: cleanup includes
iio: accel: bma220: split original driver
iio: accel: bma220: add open firmware table
iio: accel: bma220: turn power supplies on
iio: accel: bma220: reset registers during init stage
iio: accel: bma220: migrate to regmap API
iio: accel: bma220: populate buffer ts in trigger handler
iio: accel: bma220: use find_match_table fct
iio: accel: bma220: add i2c module
iio: accel: bma220: add i2c watchdog feature
iio: accel: bma220: add interrupt trigger
iio: accel: bma220: add LPF cut-off frequency mapping
iio: accel: bma220: add debugfs reg access
iio: accel: bma220: add maintainer

 MAINTAINERS                     |   7 +
 drivers/iio/accel/Kconfig       |  19 +-
 drivers/iio/accel/Makefile      |   4 +-
 drivers/iio/accel/bma220.h      |  22 ++
 drivers/iio/accel/bma220_core.c | 603 ++++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/bma220_i2c.c  |  58 ++++
 drivers/iio/accel/bma220_spi.c  | 319 ++-------------------
 7 files changed, 735 insertions(+), 297 deletions(-)

---
base-commit: 561285d048053fec8a3d6d1e3ddc60df11c393a0
change-id: 20250913-b4-bma220_improvements-ad0b3df025bb

Best regards,

Signature · 1 line
Petre Rodan <[email protected]>
author maintainer
#1 lore raw

PATCH v4 1/19 iio: accel: bma220: remove incorrect kernel-doc marking

Remove incorrect use of kernel-doc marking.

---
v4 - split from bigger patch (Andy)

---
 drivers/iio/accel/bma220_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/bma220_spi.c +1 -1
index 01592eebf05bb6b002d44c41cca1d2dd5f28350c..505ad70912571ba629f91e56a92898d8320e976f 100644
@@ -223,7 +223,7 @@ static int bma220_power(struct spi_device *spi, bool up)
 {
 	int i, ret;
 
-	/**
+	/*
 	 * The chip can be suspended/woken up by a simple register read.
 	 * So, we need up to 2 register reads of the suspend register
 	 * to make sure that the device is in the desired state.
Signature · 1 line
2.49.1
maintainer
#2 lore raw

Re: [PATCH v4 01/19] iio: accel: bma220: remove incorrect kernel-doc marking

Quoted 3 lines · On Sun, 05 Oct 2025 16:12:10 +0300 Petre Rodan <[email protected]>…

Remove incorrect use of kernel-doc marking.

hi Petre,

I'm going to pick these up as I read through them (if they are good to go!)

Applied this one,

Thanks,

Jonathan

Quoted 20 lines

---
v4 - split from bigger patch (Andy)

---
 drivers/iio/accel/bma220_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/bma220_spi.c +1 -1
index 01592eebf05bb6b002d44c41cca1d2dd5f28350c..505ad70912571ba629f91e56a92898d8320e976f 100644
@@ -223,7 +223,7 @@ static int bma220_power(struct spi_device *spi, bool up)
 {
 	int i, ret;
 
-	/**
+	/*
 	 * The chip can be suspended/woken up by a simple register read.
 	 * So, we need up to 2 register reads of the suspend register
 	 * to make sure that the device is in the desired state.
author maintainer
#3 lore raw

PATCH v4 2/19 iio: accel: bma220: relax constraints during probe()

In reply to Petre Rodan

Do not return error if the chip id being read is not the expected one.

---
v4 - split from bigger patch (Jonathan)

---
 drivers/iio/accel/bma220_spi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/iio/accel/bma220_spi.c +6 -1
index 505ad70912571ba629f91e56a92898d8320e976f..02ee6b4d51c0816a88ac258f0e5107111ec2a2bc 100644
@@ -202,10 +202,15 @@ static const struct iio_info bma220_info = {
 static int bma220_init(struct spi_device *spi)
 {
 	int ret;
+	struct device *dev = &spi->dev;
 
 	ret = bma220_read_reg(spi, BMA220_REG_ID);
+	if (ret < 0)
+		return dev_err_probe(dev, ret,
+				     "Failed to read chip id register\n");
+
 	if (ret != BMA220_CHIP_ID)
-		return -ENODEV;
+		dev_info(dev, "Unknown chip found: 0x%02x\n", ret);
 
 	/* Make sure the chip is powered on */
 	ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
Signature · 1 line
2.49.1
author maintainer
#5 lore raw

PATCH v4 3/19 iio: accel: bma220: cleanup license string

In reply to Petre Rodan

Fix checkpatch warning about use of "GPL v2" license:

Prefer "GPL" over "GPL v2" - see commit bf7fbeeae6db ("module: Cure the MODULE_LICENSE "GPL" vs. "GPL v2" bogosity")

---
v4 - split from bigger patch (Andy)

---
 drivers/iio/accel/bma220_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/bma220_spi.c +1 -1
index 02ee6b4d51c0816a88ac258f0e5107111ec2a2bc..8c313debc1dff7f4bae7c165bc555ee190996291 100644
@@ -332,4 +332,4 @@ module_spi_driver(bma220_driver);
 
 MODULE_AUTHOR("Tiberiu Breana <[email protected]>");
 MODULE_DESCRIPTION("BMA220 acceleration sensor driver");
-MODULE_LICENSE("GPL v2");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.49.1
maintainer Applied
#6 lore raw

Re: [PATCH v4 03/19] iio: accel: bma220: cleanup license string

Quoted 6 lines · On Sun, 05 Oct 2025 16:12:12 +0300 Petre Rodan <[email protected]>…

Fix checkpatch warning about use of "GPL v2" license:

Prefer "GPL" over "GPL v2" - see commit bf7fbeeae6db ("module: Cure the MODULE_LICENSE "GPL" vs. "GPL v2" bogosity")

Applied.

Quoted 17 lines

---
v4 - split from bigger patch (Andy)

---
 drivers/iio/accel/bma220_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/bma220_spi.c +1 -1
index 02ee6b4d51c0816a88ac258f0e5107111ec2a2bc..8c313debc1dff7f4bae7c165bc555ee190996291 100644
@@ -332,4 +332,4 @@ module_spi_driver(bma220_driver);
 
 MODULE_AUTHOR("Tiberiu Breana <[email protected]>");
 MODULE_DESCRIPTION("BMA220 acceleration sensor driver");
-MODULE_LICENSE("GPL v2");
+MODULE_LICENSE("GPL");
author maintainer
#7 lore raw

PATCH v4 4/19 iio: accel: bma220: shorten spi->dev calls

In reply to Petre Rodan

Provide functions easier access to device struct.

---
v4 - split from bigger patch (Andy)

---
 drivers/iio/accel/bma220_spi.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/iio/accel/bma220_spi.c +6 -5
index 8c313debc1dff7f4bae7c165bc555ee190996291..a5d2906321ae5fc67c0e1dc44651833c5e7fcb39 100644
@@ -258,8 +258,9 @@ static int bma220_probe(struct spi_device *spi)
 	int ret;
 	struct iio_dev *indio_dev;
 	struct bma220_data *data;
+	struct device *dev = &spi->dev;
 
-	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data));
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
 	if (!indio_dev)
 		return -ENOMEM;
 
@@ -278,19 +279,19 @@ static int bma220_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	ret = devm_add_action_or_reset(&spi->dev, bma220_deinit, spi);
+	ret = devm_add_action_or_reset(dev, bma220_deinit, spi);
 	if (ret)
 		return ret;
 
-	ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev,
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
 					      iio_pollfunc_store_time,
 					      bma220_trigger_handler, NULL);
 	if (ret < 0) {
-		dev_err(&spi->dev, "iio triggered buffer setup failed\n");
+		dev_err(dev, "iio triggered buffer setup failed\n");
 		return ret;
 	}
 
-	return devm_iio_device_register(&spi->dev, indio_dev);
+	return devm_iio_device_register(dev, indio_dev);
 }
 
 static int bma220_suspend(struct device *dev)
Signature · 1 line
2.49.1
author maintainer
#9 lore raw

PATCH v4 5/19 iio: accel: bma220: move bma220_power function

In reply to Petre Rodan

Move bma220_power() before bma220_init() as a precursor to a patch that removes code duplication.

---
v3->v4
- unsigned i (Andy)

---
 drivers/iio/accel/bma220_spi.c | 49 +++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 24 deletions(-)
drivers/iio/accel/bma220_spi.c +25 -24
index a5d2906321ae5fc67c0e1dc44651833c5e7fcb39..45ac0d7ee27de65b204bd2766f26024e4ed57f4c 100644
@@ -199,6 +199,31 @@ static const struct iio_info bma220_info = {
 	.read_avail		= bma220_read_avail,
 };
 
+static int bma220_power(struct spi_device *spi, bool up)
+{
+	int ret;
+	unsigned int i;
+
+	/*
+	 * The chip can be suspended/woken up by a simple register read.
+	 * So, we need up to 2 register reads of the suspend register
+	 * to make sure that the device is in the desired state.
+	 */
+	for (i = 0; i < 2; i++) {
+		ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
+		if (ret < 0)
+			return ret;
+
+		if (up && ret == BMA220_SUSPEND_SLEEP)
+			return 0;
+
+		if (!up && ret == BMA220_SUSPEND_WAKE)
+			return 0;
+	}
+
+	return -EBUSY;
+}
+
 static int bma220_init(struct spi_device *spi)
 {
 	int ret;
@@ -224,30 +249,6 @@ static int bma220_init(struct spi_device *spi)
 	return 0;
 }
 
-static int bma220_power(struct spi_device *spi, bool up)
-{
-	int i, ret;
-
-	/*
-	 * The chip can be suspended/woken up by a simple register read.
-	 * So, we need up to 2 register reads of the suspend register
-	 * to make sure that the device is in the desired state.
-	 */
-	for (i = 0; i < 2; i++) {
-		ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
-		if (ret < 0)
-			return ret;
-
-		if (up && ret == BMA220_SUSPEND_SLEEP)
-			return 0;
-
-		if (!up && ret == BMA220_SUSPEND_WAKE)
-			return 0;
-	}
-
-	return -EBUSY;
-}
-
 static void bma220_deinit(void *spi)
 {
 	bma220_power(spi, false);
Signature · 1 line
2.49.1
maintainer Applied
#10 lore raw

Re: [PATCH v4 05/19] iio: accel: bma220: move bma220_power function

Quoted 4 lines · On Sun, 05 Oct 2025 16:12:14 +0300 Petre Rodan <[email protected]>…

Move bma220_power() before bma220_init() as a precursor to a patch that removes code duplication.

Applied.

author maintainer
#11 lore raw

PATCH v4 6/19 iio: accel: bma220: cleanup includes

In reply to Petre Rodan

Tweak includes based on requirements.

---
v4 split from bigger patch (Andy)

---
 drivers/iio/accel/bma220_spi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/accel/bma220_spi.c +2 -1
index 45ac0d7ee27de65b204bd2766f26024e4ed57f4c..abff24a48e5aaa5efb05cdf1924ffea24f4da4c5 100644
@@ -6,9 +6,10 @@
  */
 
 #include <linux/bits.h>
-#include <linux/kernel.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/pm.h>
 #include <linux/types.h>
 #include <linux/spi/spi.h>
 
Signature · 1 line
2.49.1
maintainer
#13 lore raw

Re: [PATCH v4 06/19] iio: accel: bma220: cleanup includes

In reply to Petre Rodan
Quoted 3 lines · On Sun, 05 Oct 2025 16:12:15 +0300 Petre Rodan <[email protected]>…

Tweak includes based on requirements.

see next patch. I tweaked this as below

Quoted 11 lines

---
v4 split from bigger patch (Andy)

---
 drivers/iio/accel/bma220_spi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/accel/bma220_spi.c +0 -0
index 45ac0d7ee27de65b204bd2766f26024e4ed57f4c..abff24a48e5aaa5efb05cdf1924ffea24f4da4c5 100644

drivers/iio/accel/bma220_spi.c line 8

Quoted 3 lines
drivers/iio/accel/bma220_spi.c +0 -0
@@ -6,9 +6,10 @@
  */
 
 #include <linux/bits.h>

#include <linux/errno.h>

which otherwise was added in next patch with no related code changes that I could spot. It definitely should be here for EBUSY etc.

Quoted 9 lines
drivers/iio/accel/bma220_spi.c +2 -1
-#include <linux/kernel.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/pm.h>
 #include <linux/types.h>
 #include <linux/spi/spi.h>
 
author maintainer
#14 lore raw

PATCH v4 7/19 iio: accel: bma220: split original driver

In reply to Petre Rodan

In preparation for the i2c module, move the original code into multiple source files without any other functional change.

Create the additional bma220_core module which currently is not providing an abstracted bus type (this will change with the regmap patch).
Fix a few includes in the context of this patch.

---
v1->v2
- split out open firmware table modification into separate patch
- bma220_write_raw() exits without dev_err() based on similar feedback from David
- change includes in bma220.h (Jonathan)
- include bma220.h in bma220_core.c (Jonathan)
- add mutex.h and pm.h includes to bma220_core.c
- cleanup struct spacing in bma220_spi.c
v2->v3
- keep depends on SPI (David)
- fix a few includes in bma220_spi.c (Jonathan)
v2->v3
- keep depends on SPI (David)
- fix a few includes in bma220_spi.c (Jonathan)
- mention new includes in commit body (Jonathan)
v4 move some of the changes into precursor patches (01-07) (Andy)

---
 drivers/iio/accel/Kconfig       |   8 +-
 drivers/iio/accel/Makefile      |   3 +-
 drivers/iio/accel/bma220.h      |  18 +++
 drivers/iio/accel/bma220_core.c | 319 ++++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/bma220_spi.c  | 314 ++-------------------------------------
 5 files changed, 357 insertions(+), 305 deletions(-)
drivers/iio/accel/Kconfig +7 -1
index 8c3f7cf55d5fa432a4d4662b184a46cd59c3ebca..4648be329917a3054615ed324156d67f53baefb6 100644
@@ -221,12 +221,18 @@ config BMA220
 	depends on SPI
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
+	select BMA220_SPI if SPI
 	help
 	  Say yes here to add support for the Bosch BMA220 triaxial
 	  acceleration sensor.
 
 	  To compile this driver as a module, choose M here: the
-	  module will be called bma220_spi.
+	  module will be called bma220_core and you will also get
+	  bma220_spi if SPI is enabled.
+
+config BMA220_SPI
+	tristate
+	depends on BMA220
 
 config BMA400
 	tristate "Bosch BMA400 3-Axis Accelerometer Driver"
drivers/iio/accel/Makefile +2 -1
index ca8569e25aba31c3ae3437abf8506addbf5edffa..56a9f848f7f913633bc2a628c1ac5c9190774b9d 100644
@@ -25,7 +25,8 @@ obj-$(CONFIG_ADXL380) += adxl380.o
 obj-$(CONFIG_ADXL380_I2C) += adxl380_i2c.o
 obj-$(CONFIG_ADXL380_SPI) += adxl380_spi.o
 obj-$(CONFIG_BMA180) += bma180.o
-obj-$(CONFIG_BMA220) += bma220_spi.o
+obj-$(CONFIG_BMA220) += bma220_core.o
+obj-$(CONFIG_BMA220_SPI) += bma220_spi.o
 obj-$(CONFIG_BMA400) += bma400_core.o
 obj-$(CONFIG_BMA400_I2C) += bma400_i2c.o
 obj-$(CONFIG_BMA400_SPI) += bma400_spi.o
drivers/iio/accel/bma220.h new file +18 -0
new file mode 100644
index 0000000000000000000000000000000000000000..dea34244b4fc4971841dc60d79db6c7db27bea20
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Forward declarations needed by the bma220 sources.
+ *
+ * Copyright 2025 Petre Rodan <[email protected]>
+ */
+
+#ifndef _BMA220_H
+#define _BMA220_H
+
+#include <linux/pm.h>
+
+extern const struct dev_pm_ops bma220_pm_ops;
+struct spi_device;
+
+int bma220_common_probe(struct spi_device *dev);
+
+#endif
drivers/iio/accel/bma220_core.c new file +319 -0

319 lines not on this page · raw message

drivers/iio/accel/bma220_spi.c +11 -303

345 lines not on this page · raw message

Signature · 1 line
2.49.1
maintainer
#15 lore raw

Re: [PATCH v4 07/19] iio: accel: bma220: split original driver

Quoted 9 lines · On Sun, 05 Oct 2025 16:12:16 +0300 Petre Rodan <[email protected]>…

In preparation for the i2c module, move the original code into multiple source files without any other functional change.

Create the additional bma220_core module which currently is not providing an abstracted bus type (this will change with the regmap patch).
Fix a few includes in the context of this patch.

It required a bit of hand tweaking after the include tweak I made in the previous patch. Also due to comments in here I tweaked a bit more:

Please check the result on the iio.git / testing branch.

Whilst I'm not entirely sure Andy won't want to take another look at this it seemed ok to apply a bit speculatively,

Thanks,

Jonathan

drivers/iio/accel/bma220_core.c +1 -0
index 00fe1064486a..050282f20d90 100644
@@ -6,6 +6,7 @@
  */
 
 #include <linux/bits.h>
+#include <linux/errno.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
drivers/iio/accel/bma220_spi.c +2 -3
index 70b8bd94895e..761f475a5942 100644
@@ -5,7 +5,6 @@
  * Copyright (c) 2016,2020 Intel Corporation.
  */
 
-#include <linux/errno.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/types.h>
@@ -19,12 +18,12 @@ static int bma220_spi_probe(struct spi_device *spi)
 }
 
 static const struct spi_device_id bma220_spi_id[] = {
-       { "bma220", 0 },
+       {"bma220", 0},
        { }
 };
 
 static const struct acpi_device_id bma220_acpi_id[] = {
-       { "BMA0220", 0 },
+       {"BMA0220", 0},
        { }
 };
 MODULE_DEVICE_TABLE(spi, bma220_spi_id);
Quoted 31 lines

---
v1->v2
- split out open firmware table modification into separate patch
- bma220_write_raw() exits without dev_err() based on similar feedback from David
- change includes in bma220.h (Jonathan)
- include bma220.h in bma220_core.c (Jonathan)
- add mutex.h and pm.h includes to bma220_core.c
- cleanup struct spacing in bma220_spi.c
v2->v3
- keep depends on SPI (David)
- fix a few includes in bma220_spi.c (Jonathan)
v2->v3
- keep depends on SPI (David)
- fix a few includes in bma220_spi.c (Jonathan)
- mention new includes in commit body (Jonathan)
v4 move some of the changes into precursor patches (01-07) (Andy)

---
 drivers/iio/accel/Kconfig       |   8 +-
 drivers/iio/accel/Makefile      |   3 +-
 drivers/iio/accel/bma220.h      |  18 +++
 drivers/iio/accel/bma220_core.c | 319 ++++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/bma220_spi.c  | 314 ++-------------------------------------
 5 files changed, 357 insertions(+), 305 deletions(-)
drivers/iio/accel/bma220_core.c new file +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..00fe1064486aa469f7ad15593027c7ec86197365

drivers/iio/accel/bma220_core.c line 8

Quoted 8 lines
drivers/iio/accel/bma220_core.c new file +8 -0
@@ -0,0 +1,319 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * BMA220 Digital triaxial acceleration sensor driver
+ *
+ * Copyright (c) 2016,2020 Intel Corporation.
+ */
+
+#include <linux/bits.h>

Looks like this needs errno.h as per the one you added to _spi.c below.

Quoted 45 lines
drivers/iio/accel/bma220_core.c new file +45 -0
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/pm.h>
+#include <linux/types.h>
+#include <linux/spi/spi.h>
+
+#include <linux/iio/buffer.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+
+#include "bma220.h"
+
+#define BMA220_REG_ID				0x00
+#define BMA220_REG_ACCEL_X			0x02
+#define BMA220_REG_ACCEL_Y			0x03
+#define BMA220_REG_ACCEL_Z			0x04
+#define BMA220_REG_RANGE			0x11
+#define BMA220_REG_SUSPEND			0x18
+
+#define BMA220_CHIP_ID				0xDD
+#define BMA220_READ_MASK			BIT(7)
+#define BMA220_RANGE_MASK			GENMASK(1, 0)
+#define BMA220_SUSPEND_SLEEP			0xFF
+#define BMA220_SUSPEND_WAKE			0x00
+
+#define BMA220_DEVICE_NAME			"bma220"
+
+#define BMA220_ACCEL_CHANNEL(index, reg, axis) {			\
+	.type = IIO_ACCEL,						\
+	.address = reg,							\
+	.modified = 1,							\
+	.channel2 = IIO_MOD_##axis,					\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),			\
+	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),		\
+	.scan_index = index,						\
+	.scan_type = {							\
+		.sign = 's',						\
+		.realbits = 6,						\
+		.storagebits = 8,					\
+		.shift = 2,						\
+		.endianness = IIO_CPU,					\
+	},								\

drivers/iio/accel/bma220_core.c line 63

Quoted 10 lines
drivers/iio/accel/bma220_core.c new file +10 -0
+}
+
+enum bma220_axis {
+	AXIS_X,
+	AXIS_Y,
+	AXIS_Z,
+};
+
+static const int bma220_scale_table[][2] = {
+	{0, 623000}, {1, 248000}, {2, 491000}, {4, 983000},

If you do a white space bracket related separate patch as suggested below feel free to include this one as:

	{ 0, 623000 }, { 1, 248000 }, { 2, 491000 }, { 4, 983000 },

But don't do it in this split patch. I don't mind that much if you don't do it at all.

drivers/iio/accel/bma220_spi.c line 8

Quoted 13 lines
drivers/iio/accel/bma220_core.c new file +1 -0
+};
drivers/iio/accel/bma220_spi.c +1 -1
index abff24a48e5aaa5efb05cdf1924ffea24f4da4c5..70b8bd94895e95936c7294271b5d46d9ec9903c6 100644
@@ -5,334 +5,42 @@
  * Copyright (c) 2016,2020 Intel Corporation.
  */
 
-#include <linux/bits.h>
+#include <linux/errno.h>

It seems rather unlikely that the split out spi.c file needs this but the previous more generic one that incorporate pretty much all this code did not.
I checked and it should always have been here so I've added it by tweaking patch 6.

Quoted 13 lines
drivers/iio/accel/bma220_spi.c +1 -7
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
-#include <linux/mutex.h>
-#include <linux/pm.h>
 #include <linux/types.h>
 #include <linux/spi/spi.h>
 
-#include <linux/iio/buffer.h>
-#include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>
-#include <linux/iio/trigger_consumer.h>
-#include <linux/iio/triggered_buffer.h>
+#include "bma220.h"

...

drivers/iio/accel/bma220_spi.c

Quoted 12 lines
drivers/iio/accel/bma220_spi.c +2 -7
-static int bma220_resume(struct device *dev)
-{
-	struct spi_device *spi = to_spi_device(dev);
-
-	return bma220_power(spi, true);
+	return bma220_common_probe(spi);
 }
-static DEFINE_SIMPLE_DEV_PM_OPS(bma220_pm_ops, bma220_suspend, bma220_resume);
 
 static const struct spi_device_id bma220_spi_id[] = {
-	{"bma220", 0},
+	{ "bma220", 0 },

Whist good this is technically an unrelated white space change so shouldn't really be in this patch. However if this is only thing that needs a new spin lets not bother. Sometimes it's better to just be a little relaxed on patch split up so we don't waste time on more versions!

drivers/iio/accel/bma220_spi.c

Quoted 6 lines
drivers/iio/accel/bma220_spi.c +1 -1
 	{ }
 };
 
 static const struct acpi_device_id bma220_acpi_id[] = {
-	{"BMA0220", 0},
+	{ "BMA0220", 0 },

Same here.

Quoted 24 lines
drivers/iio/accel/bma220_spi.c +5 -4
 	{ }
 };
 MODULE_DEVICE_TABLE(spi, bma220_spi_id);
 
-static struct spi_driver bma220_driver = {
+static struct spi_driver bma220_spi_driver = {
 	.driver = {
 		.name = "bma220_spi",
 		.pm = pm_sleep_ptr(&bma220_pm_ops),
 		.acpi_match_table = bma220_acpi_id,
 	},
-	.probe =            bma220_probe,
+	.probe =            bma220_spi_probe,
 	.id_table =         bma220_spi_id,
 };
-module_spi_driver(bma220_driver);
+module_spi_driver(bma220_spi_driver);
 
 MODULE_AUTHOR("Tiberiu Breana <[email protected]>");
-MODULE_DESCRIPTION("BMA220 acceleration sensor driver");
+MODULE_DESCRIPTION("BMA220 triaxial acceleration sensor spi driver");
 MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("IIO_BOSCH_BMA220");
author maintainer
#16 lore raw

Re: [PATCH v4 07/19] iio: accel: bma220: split original driver

Hi Jonathan,

Quoted 11 lines · Jonathan Cameron
Quoted 8 lines · On Sun, 05 Oct 2025 16:12:16 +0300 Petre Rodan <[email protected]>…

In preparation for the i2c module, move the original code into multiple source files without any other functional change.

Create the additional bma220_core module which currently is not providing an abstracted bus type (this will change with the regmap patch).
Fix a few includes in the context of this patch.

Quoted 6 lines
Quoted 1 line

It required a bit of hand tweaking after the include tweak I made in the previous patch. Also due to comments in here I tweaked a bit more:

Please check the result on the iio.git / testing branch.

I included two trivial patches in the new series 'bma220 events' that do a pre-cleanup of this driver.

Thank you everyone for the feedback.

best regards,
peter

author maintainer
#17 lore raw

PATCH v4 8/19 iio: accel: bma220: add open firmware table

In reply to Petre Rodan

Add open firmware entry to the spi driver.

---
v1->v2 split from bigger patch
v3->v4 no change

---
 drivers/iio/accel/bma220_spi.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/iio/accel/bma220_spi.c +7 -0
index 70b8bd94895e95936c7294271b5d46d9ec9903c6..b27592591d2817e2c3f3780f4307e3a76c7e06cb 100644
@@ -29,10 +29,17 @@ static const struct acpi_device_id bma220_acpi_id[] = {
 };
 MODULE_DEVICE_TABLE(spi, bma220_spi_id);
 
+static const struct of_device_id bma220_of_spi_match[] = {
+	{ .compatible = "bosch,bma220" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, bma220_of_spi_match);
+
 static struct spi_driver bma220_spi_driver = {
 	.driver = {
 		.name = "bma220_spi",
 		.pm = pm_sleep_ptr(&bma220_pm_ops),
+		.of_match_table = bma220_of_spi_match,
 		.acpi_match_table = bma220_acpi_id,
 	},
 	.probe =            bma220_spi_probe,
Signature · 1 line
2.49.1
author maintainer
#19 lore raw

PATCH v4 9/19 iio: accel: bma220: turn power supplies on

In reply to Petre Rodan

Add devm_regulator_bulk_get_enable() to device probe().

---
v1->v2 split from larger patch
v2->v3 change commit desc (Jonathan)
v4 dev ptr (Andy)

---
 drivers/iio/accel/bma220_core.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/iio/accel/bma220_core.c +7 -0
index 00fe1064486aa469f7ad15593027c7ec86197365..319a3d6867ee5ac2da64c9baf02a760865302ee8 100644
@@ -10,6 +10,7 @@
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/pm.h>
+#include <linux/regulator/consumer.h>
 #include <linux/types.h>
 #include <linux/spi/spi.h>
 
@@ -230,6 +231,12 @@ static int bma220_init(struct spi_device *spi)
 {
 	int ret;
 	struct device *dev = &spi->dev;
+	static const char * const regulator_names[] = { "vddd", "vddio", "vdda" };
+
+	ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names),
+					     regulator_names);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to get regulators\n");
 
 	ret = bma220_read_reg(spi, BMA220_REG_ID);
 	if (ret < 0)
Signature · 1 line
2.49.1
author maintainer
#21 lore raw

PATCH v4 10/19 iio: accel: bma220: reset registers during init stage

In reply to Petre Rodan

Bring all configuration registers to default values during device probe().
Remove trivial code duplication regarding bma220_power() in _init()

---
v4 dev ptr (Andy)

---
 drivers/iio/accel/bma220_core.c | 44 +++++++++++++++++++++++++++++++++--------
 1 file changed, 36 insertions(+), 8 deletions(-)
drivers/iio/accel/bma220_core.c +36 -8
index 319a3d6867ee5ac2da64c9baf02a760865302ee8..1b118a9fce3f16f0cd805a68b9887c6eaf24973a 100644
@@ -28,12 +28,15 @@
 #define BMA220_REG_ACCEL_Z			0x04
 #define BMA220_REG_RANGE			0x11
 #define BMA220_REG_SUSPEND			0x18
+#define BMA220_REG_SOFTRESET			0x19
 
 #define BMA220_CHIP_ID				0xDD
 #define BMA220_READ_MASK			BIT(7)
 #define BMA220_RANGE_MASK			GENMASK(1, 0)
 #define BMA220_SUSPEND_SLEEP			0xFF
 #define BMA220_SUSPEND_WAKE			0x00
+#define BMA220_RESET_MODE			0xFF
+#define BMA220_NONRESET_MODE			0x00
 
 #define BMA220_DEVICE_NAME			"bma220"
 
@@ -202,6 +205,31 @@ static const struct iio_info bma220_info = {
 	.read_avail		= bma220_read_avail,
 };
 
+static int bma220_reset(struct spi_device *spi, bool up)
+{
+	int ret;
+	unsigned int i;
+
+	/*
+	 * The chip can be reset by a simple register read.
+	 * We need up to 2 register reads of the softreset register
+	 * to make sure that the device is in the desired state.
+	 */
+	for (i = 0; i < 2; i++) {
+		ret = bma220_read_reg(spi, BMA220_REG_SOFTRESET);
+		if (ret < 0)
+			return ret;
+
+		if (up && ret == BMA220_RESET_MODE)
+			return 0;
+
+		if (!up && ret == BMA220_NONRESET_MODE)
+			return 0;
+	}
+
+	return -EBUSY;
+}
+
 static int bma220_power(struct spi_device *spi, bool up)
 {
 	int ret;
@@ -246,14 +274,14 @@ static int bma220_init(struct spi_device *spi)
 	if (ret != BMA220_CHIP_ID)
 		dev_info(dev, "Unknown chip found: 0x%02x\n", ret);
 
-	/* Make sure the chip is powered on */
-	ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
-	if (ret == BMA220_SUSPEND_WAKE)
-		ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
-	if (ret < 0)
-		return ret;
-	if (ret == BMA220_SUSPEND_WAKE)
-		return -EBUSY;
+	/* Make sure the chip is powered on and config registers are reset */
+	ret = bma220_power(spi, true);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to power-on chip\n");
+
+	ret = bma220_reset(spi, true);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to soft reset chip\n");
 
 	return 0;
 }
Signature · 1 line
2.49.1
maintainer Applied
#22 lore raw

Re: [PATCH v4 10/19] iio: accel: bma220: reset registers during init stage

Quoted 6 lines · On Sun, 05 Oct 2025 16:12:19 +0300 Petre Rodan <[email protected]>…

Bring all configuration registers to default values during device probe().
Remove trivial code duplication regarding bma220_power() in _init()

Applied.

author maintainer
#23 lore raw

PATCH v4 11/19 iio: accel: bma220: migrate to regmap API

In reply to Petre Rodan

Switch to regmap API.

---
v1->v2
- split out into more patches (Jonathan)
v2->v3
- split out into even more patches (Jonathan)
- use dev_err_probe() (Jonathan)
v4 remove dev from priv struct (Andy)

---
 drivers/iio/accel/Kconfig       |   2 +
 drivers/iio/accel/bma220.h      |   7 +-
 drivers/iio/accel/bma220_core.c | 231 +++++++++++++++++++++++++++-------------
 drivers/iio/accel/bma220_spi.c  |  10 +-
 4 files changed, 173 insertions(+), 77 deletions(-)
drivers/iio/accel/Kconfig +2 -0
index 4648be329917a3054615ed324156d67f53baefb6..988fe4b1f9a52c2e671ea30d8590f25ee1685ac7 100644
@@ -219,6 +219,7 @@ config BMA180
 config BMA220
 	tristate "Bosch BMA220 3-Axis Accelerometer Driver"
 	depends on SPI
+	select REGMAP
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
 	select BMA220_SPI if SPI
@@ -232,6 +233,7 @@ config BMA220
 
 config BMA220_SPI
 	tristate
+	select REGMAP_SPI
 	depends on BMA220
 
 config BMA400
drivers/iio/accel/bma220.h +5 -2
index dea34244b4fc4971841dc60d79db6c7db27bea20..695f491bc5a03008f26fe8602ba633456159fb1d 100644
@@ -9,10 +9,13 @@
 #define _BMA220_H
 
 #include <linux/pm.h>
+#include <linux/regmap.h>
 
+struct device;
+
+extern const struct regmap_config bma220_spi_regmap_config;
 extern const struct dev_pm_ops bma220_pm_ops;
-struct spi_device;
 
-int bma220_common_probe(struct spi_device *dev);
+int bma220_common_probe(struct device *dev, struct regmap *regmap, int irq);
 
 #endif
drivers/iio/accel/bma220_core.c +157 -74

424 lines not on this page · raw message

drivers/iio/accel/bma220_spi.c +9 -1
index b27592591d2817e2c3f3780f4307e3a76c7e06cb..8990155ac0cd36ace08d1192b4dda3c275ad675e 100644
@@ -8,6 +8,7 @@
 #include <linux/errno.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
+#include <linux/regmap.h>
 #include <linux/types.h>
 #include <linux/spi/spi.h>
 
@@ -15,7 +16,14 @@
 
 static int bma220_spi_probe(struct spi_device *spi)
 {
-	return bma220_common_probe(spi);
+	struct regmap *regmap;
+
+	regmap = devm_regmap_init_spi(spi, &bma220_spi_regmap_config);
+	if (IS_ERR(regmap))
+		return dev_err_probe(&spi->dev, PTR_ERR(regmap),
+				     "failed to create regmap\n");
+
+	return bma220_common_probe(&spi->dev, regmap, spi->irq);
 }
 
 static const struct spi_device_id bma220_spi_id[] = {
Signature · 1 line
2.49.1
maintainer Applied
#24 lore raw

Re: [PATCH v4 11/19] iio: accel: bma220: migrate to regmap API

Quoted 3 lines · On Sun, 05 Oct 2025 16:12:20 +0300 Petre Rodan <[email protected]>…

Switch to regmap API.

This took a bit of hand applying due to my messing around with headers in earlier patches. Please check I didn't mess it up!

Applied.

Thanks,

Jonathan

author maintainer
#25 lore raw

PATCH v4 12/19 iio: accel: bma220: populate buffer ts in trigger handler

In reply to Petre Rodan

Populate buffer timestamps in trigger handler since not all triggers can run the top half handler that provides pf->timestamp.

Fixes failing unit test that triggers based on the INT signal.

---
v2->v3 split out from bigger patch (Jonathan)
v4 more verbose commit msg (Jonathan)

---
 drivers/iio/accel/bma220_core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/accel/bma220_core.c +2 -3
index 7b1e87c6932a3a6698651e528fb8182c03a2432e..ec7409db83f81882043653cd70e3205500348994 100644
@@ -186,7 +186,7 @@ static irqreturn_t bma220_trigger_handler(int irq, void *p)
 		return IRQ_NONE;
 
 	iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan),
-				    pf->timestamp);
+				    iio_get_time_ns(indio_dev));
 	iio_trigger_notify_done(indio_dev->trig);
 
 	return IRQ_HANDLED;
@@ -404,8 +404,7 @@ int bma220_common_probe(struct device *dev, struct regmap *regmap, int irq)
 	if (ret)
 		return ret;
 
-	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
-					      iio_pollfunc_store_time,
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
 					      bma220_trigger_handler, NULL);
 	if (ret < 0)
 		dev_err_probe(dev, ret, "iio triggered buffer setup failed\n");
Signature · 1 line
2.49.1
maintainer Applied
#26 lore raw

Re: [PATCH v4 12/19] iio: accel: bma220: populate buffer ts in trigger handler

Quoted 7 lines · On Sun, 05 Oct 2025 16:12:21 +0300 Petre Rodan <[email protected]>…

Populate buffer timestamps in trigger handler since not all triggers can run the top half handler that provides pf->timestamp.

Fixes failing unit test that triggers based on the INT signal.

I hope that we will at somepoint get the generic code that would make this unnecessary but it's not there yet so fair enough.

Applied.

author maintainer
#27 lore raw

Re: [PATCH v4 12/19] iio: accel: bma220: populate buffer ts in trigger handler

Hello Jonathan.

I was a bit worried and I hope you've fully recovered from the flu.

And yes, it also had to restart the rebase multiple times because either I forgot to add bma220.h or I tweaked a few innocent lines in the 4-th patch and they had a ripple effect on everything that followed. Thank you for adding the finishing touches.

Quoted 1 line

Applied.

I promise to test these out quickly, but please do a push on your testing branch (the last commit I can see is the previous patch).

best regards,
peter

author maintainer
#28 lore raw

PATCH v4 13/19 iio: accel: bma220: use find_match_table fct

In reply to Petre Rodan

Clean up the code a bit by using a find_match_table function.

---
v2->v3 split out from bigger patch (Jonathan)
v4 no change

---
 drivers/iio/accel/bma220_core.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
drivers/iio/accel/bma220_core.c +16 -7
index ec7409db83f81882043653cd70e3205500348994..42d5acce0a8387734d932c77fec9777a7a01f774 100644
@@ -221,11 +221,23 @@ static int bma220_read_raw(struct iio_dev *indio_dev,
 	return -EINVAL;
 }
 
+static int bma220_find_match_2dt(const int (*tbl)[2], const int n,
+				 const int val, const int val2)
+{
+	int i;
+
+	for (i = 0; i < n; i++) {
+		if (tbl[i][0] == val && tbl[i][1] == val2)
+			return i;
+	}
+
+	return -EINVAL;
+}
+
 static int bma220_write_raw(struct iio_dev *indio_dev,
 			    struct iio_chan_spec const *chan,
 			    int val, int val2, long mask)
 {
-	int i;
 	int ret;
 	int index = -1;
 	struct bma220_data *data = iio_priv(indio_dev);
@@ -234,12 +246,9 @@ static int bma220_write_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_SCALE:
-		for (i = 0; i < ARRAY_SIZE(bma220_scale_table); i++)
-			if (val == bma220_scale_table[i][0] &&
-			    val2 == bma220_scale_table[i][1]) {
-				index = i;
-				break;
-			}
+		index = bma220_find_match_2dt(bma220_scale_table,
+					      ARRAY_SIZE(bma220_scale_table),
+					      val, val2);
 		if (index < 0)
 			return -EINVAL;
 
Signature · 1 line
2.49.1
author maintainer
#30 lore raw

PATCH v4 14/19 iio: accel: bma220: add i2c module

In reply to Petre Rodan

Add the bma220_i2c module.

Note that this kernel module transparently shifts all register addresses 1 bit to the left, so all functions will operate based on the SPI memory map.

---
v1->v2 no change
v2->v3
- depends I2C || SPI (David)
- change extern const struct order (David)
- remove unused includes (David)
v4 no change

---
 drivers/iio/accel/Kconfig       | 11 ++++++--
 drivers/iio/accel/Makefile      |  1 +
 drivers/iio/accel/bma220.h      |  1 +
 drivers/iio/accel/bma220_core.c | 18 +++++++++++++
 drivers/iio/accel/bma220_i2c.c  | 58 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 87 insertions(+), 2 deletions(-)
drivers/iio/accel/Kconfig +9 -2
index 988fe4b1f9a52c2e671ea30d8590f25ee1685ac7..76911278fb217bd3e429c427b873fb7eae26420e 100644
@@ -218,10 +218,11 @@ config BMA180
 
 config BMA220
 	tristate "Bosch BMA220 3-Axis Accelerometer Driver"
-	depends on SPI
+	depends on I2C || SPI
 	select REGMAP
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
+	select BMA220_I2C if I2C
 	select BMA220_SPI if SPI
 	help
 	  Say yes here to add support for the Bosch BMA220 triaxial
@@ -229,7 +230,13 @@ config BMA220
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called bma220_core and you will also get
-	  bma220_spi if SPI is enabled.
+	  bma220_i2c if I2C is enabled and bma220_spi if SPI is
+	  enabled.
+
+config BMA220_I2C
+	tristate
+	select REGMAP_I2C
+	depends on BMA220
 
 config BMA220_SPI
 	tristate
drivers/iio/accel/Makefile +1 -0
index 56a9f848f7f913633bc2a628c1ac5c9190774b9d..fa440a85928398fee927081f605595ba9fbc4ad9 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_ADXL380_I2C) += adxl380_i2c.o
 obj-$(CONFIG_ADXL380_SPI) += adxl380_spi.o
 obj-$(CONFIG_BMA180) += bma180.o
 obj-$(CONFIG_BMA220) += bma220_core.o
+obj-$(CONFIG_BMA220_I2C) += bma220_i2c.o
 obj-$(CONFIG_BMA220_SPI) += bma220_spi.o
 obj-$(CONFIG_BMA400) += bma400_core.o
 obj-$(CONFIG_BMA400_I2C) += bma400_i2c.o
drivers/iio/accel/bma220.h +1 -0
index 695f491bc5a03008f26fe8602ba633456159fb1d..e53ca63de54b4e81df0908b11d0fb7f03a86dbdc 100644
@@ -13,6 +13,7 @@
 
 struct device;
 
+extern const struct regmap_config bma220_i2c_regmap_config;
 extern const struct regmap_config bma220_spi_regmap_config;
 extern const struct dev_pm_ops bma220_pm_ops;
 
drivers/iio/accel/bma220_core.c +18 -0
index 42d5acce0a8387734d932c77fec9777a7a01f774..a3faf1f5ec6d79f2c6105697b404d6eb1f4501db 100644
@@ -172,6 +172,24 @@ const struct regmap_config bma220_spi_regmap_config = {
 };
 EXPORT_SYMBOL_NS_GPL(bma220_spi_regmap_config, "IIO_BOSCH_BMA220");
 
+/*
+ * Based on the datasheet the memory map differs between the SPI and the I2C
+ * implementations. I2C register addresses are simply shifted to the left
+ * by 1 bit yet the register size remains unchanged.
+ * This driver employs the SPI memory map to correlate register names to
+ * addresses regardless of the bus type.
+ */
+
+const struct regmap_config bma220_i2c_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.reg_shift = -1,
+	.max_register = BMA220_REG_SOFTRESET,
+	.cache_type = REGCACHE_NONE,
+	.writeable_reg = bma220_is_writable_reg,
+};
+EXPORT_SYMBOL_NS_GPL(bma220_i2c_regmap_config, "IIO_BOSCH_BMA220");
+
 static irqreturn_t bma220_trigger_handler(int irq, void *p)
 {
 	int ret;
drivers/iio/accel/bma220_i2c.c new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
2.49.1
maintainer
#31 lore raw

Re: [PATCH v4 14/19] iio: accel: bma220: add i2c module

Quoted 7 lines · On Sun, 05 Oct 2025 16:12:23 +0300 Petre Rodan <[email protected]>…

Add the bma220_i2c module.

Note that this kernel module transparently shifts all register addresses 1 bit to the left, so all functions will operate based on the SPI memory map.

Applied. Note that it was only when I reached here I realized I failed to add the bma220.h when hand applying things earlier. Anyhow I went back and fixed that up, but there a few little differences in ordering. I took the view it was close enough that I didn't go back and do it a 3rd time. Nothing affects eventual state, just position of the temporary struct spi_device; forwards declaration I think.

Anyhow, after that this applied cleanly so all good

Thanks,

Jonathan

author maintainer
#32 lore raw

PATCH v4 15/19 iio: accel: bma220: add i2c watchdog feature

In reply to Petre Rodan

Sometimes the sensor gets stuck and enters a condition in which it pulls SDA low, thus making the entire i2c bus unusable.
This problem is mitigated by activating a 1ms watchdog implemented in the sensor.

---
v1->v2
- hardcode 1ms timer watchdog to any i2c-based sensor instead of configuring a dt-based property
- rename bma220_wdt() to bma220_set_wdt()
v2->v4 no change

---
 drivers/iio/accel/bma220_core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/iio/accel/bma220_core.c +14 -0
index a3faf1f5ec6d79f2c6105697b404d6eb1f4501db..a957751be40c63c25963283be813db97f73bf004 100644
@@ -10,6 +10,7 @@
 #include <linux/bitfield.h>
 #include <linux/cleanup.h>
 #include <linux/device.h>
+#include <linux/i2c.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
@@ -355,6 +356,12 @@ static int bma220_power(struct bma220_data *data, bool up)
 	return -EBUSY;
 }
 
+static int bma220_set_wdt(struct bma220_data *data, const u8 val)
+{
+	return regmap_update_bits(data->regmap, BMA220_REG_WDT, BMA220_WDT_MASK,
+				  FIELD_PREP(BMA220_WDT_MASK, val));
+}
+
 static int bma220_init(struct device *dev, struct bma220_data *data)
 {
 	int ret;
@@ -383,6 +390,13 @@ static int bma220_init(struct device *dev, struct bma220_data *data)
 	if (ret)
 		return dev_err_probe(dev, ret, "Failed to soft reset chip\n");
 
+	if (i2c_verify_client(dev)) {
+		ret = bma220_set_wdt(data, BMA220_WDT_1MS);
+		if (ret)
+			return dev_err_probe(dev, ret,
+					     "Failed to set i2c watchdog\n");
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.49.1
maintainer Applied
#33 lore raw

Re: [PATCH v4 15/19] iio: accel: bma220: add i2c watchdog feature

Quoted 6 lines · On Sun, 05 Oct 2025 16:12:24 +0300 Petre Rodan <[email protected]>…

Sometimes the sensor gets stuck and enters a condition in which it pulls SDA low, thus making the entire i2c bus unusable.
This problem is mitigated by activating a 1ms watchdog implemented in the sensor.

Applied.

Thanks.

J

author maintainer
#34 lore raw

PATCH v4 16/19 iio: accel: bma220: add interrupt trigger

In reply to Petre Rodan

Add interrupt trigger.

---
v1->v2 no change, just patch split
v2->v3 replace regmap_bulk_read with regmap_read (Jonathan)
(I just realized BMA220_REG_IF0 is never used, even by future event patches)
v4 fix compilation err

---
 drivers/iio/accel/bma220_core.c | 58 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
drivers/iio/accel/bma220_core.c +58 -0
index a957751be40c63c25963283be813db97f73bf004..8f0cbd0aacb92a21afc57aaa350547d0c767d4b6 100644
@@ -22,6 +22,7 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
+#include <linux/iio/trigger.h>
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
 
@@ -123,6 +124,7 @@ struct bma220_data {
 	struct regmap *regmap;
 	struct mutex lock;
 	u8 range_idx;
+	struct iio_trigger *trig;
 	struct {
 		s8 chans[3];
 		/* Ensure timestamp is naturally aligned. */
@@ -191,6 +193,22 @@ const struct regmap_config bma220_i2c_regmap_config = {
 };
 EXPORT_SYMBOL_NS_GPL(bma220_i2c_regmap_config, "IIO_BOSCH_BMA220");
 
+static int bma220_data_rdy_trigger_set_state(struct iio_trigger *trig,
+					     bool state)
+{
+	struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
+	struct bma220_data *data = iio_priv(indio_dev);
+
+	return regmap_update_bits(data->regmap, BMA220_REG_IE0,
+				  BMA220_INT_EN_DRDY_MSK,
+				  FIELD_PREP(BMA220_INT_EN_DRDY_MSK, state));
+}
+
+static const struct iio_trigger_ops bma220_trigger_ops = {
+	.set_trigger_state = &bma220_data_rdy_trigger_set_state,
+	.validate_device = &iio_trigger_validate_own_device,
+};
+
 static irqreturn_t bma220_trigger_handler(int irq, void *p)
 {
 	int ret;
@@ -413,6 +431,23 @@ static void bma220_deinit(void *data_ptr)
 			 ERR_PTR(ret));
 }
 
+static irqreturn_t bma220_irq_handler(int irq, void *private)
+{
+	struct iio_dev *indio_dev = private;
+	struct bma220_data *data = iio_priv(indio_dev);
+	int ret;
+	unsigned int bma220_reg_if1;
+
+	ret = regmap_read(data->regmap, BMA220_REG_IF1, &bma220_reg_if1);
+	if (ret)
+		return IRQ_NONE;
+
+	if (FIELD_GET(BMA220_IF_DRDY, bma220_reg_if1))
+		iio_trigger_poll_nested(data->trig);
+
+	return IRQ_HANDLED;
+}
+
 int bma220_common_probe(struct device *dev, struct regmap *regmap, int irq)
 {
 	int ret;
@@ -441,6 +476,29 @@ int bma220_common_probe(struct device *dev, struct regmap *regmap, int irq)
 	indio_dev->num_channels = ARRAY_SIZE(bma220_channels);
 	indio_dev->available_scan_masks = bma220_accel_scan_masks;
 
+	if (irq > 0) {
+		data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
+						    indio_dev->name,
+						    iio_device_id(indio_dev));
+		if (!data->trig)
+			return -ENOMEM;
+
+		data->trig->ops = &bma220_trigger_ops;
+		iio_trigger_set_drvdata(data->trig, indio_dev);
+
+		ret = devm_iio_trigger_register(dev, data->trig);
+		if (ret)
+			return dev_err_probe(dev, ret,
+					     "iio trigger register fail\n");
+		indio_dev->trig = iio_trigger_get(data->trig);
+		ret = devm_request_threaded_irq(dev, irq, NULL,
+						&bma220_irq_handler, IRQF_ONESHOT,
+						indio_dev->name, indio_dev);
+		if (ret)
+			return dev_err_probe(dev, ret,
+					     "request irq %d failed\n", irq);
+	}
+
 	ret = devm_add_action_or_reset(dev, bma220_deinit, data);
 	if (ret)
 		return ret;
Signature · 1 line
2.49.1
author maintainer
#36 lore raw

PATCH v4 17/19 iio: accel: bma220: add LPF cut-off frequency mapping

In reply to Petre Rodan

Add mapping for the low pass filter cut-off frequency.
Make valid values visible for both the cut-off frequency and the scale.

---
v1->v2 rename variables to include unit capitalization (dB, Hz) v2->v3 make comment one-liner (Jonathan)
v4 no change

---
 drivers/iio/accel/bma220_core.c | 59 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)
drivers/iio/accel/bma220_core.c +58 -1
index 8f0cbd0aacb92a21afc57aaa350547d0c767d4b6..7109759e28397d2660f17707124a8803a254cb14 100644
@@ -93,13 +93,23 @@
 
 #define BMA220_DEVICE_NAME			"bma220"
 
+#define BMA220_COF_1000Hz			0x0
+#define BMA220_COF_500Hz			0x1
+#define BMA220_COF_250Hz			0x2
+#define BMA220_COF_125Hz			0x3
+#define BMA220_COF_64Hz				0x4
+#define BMA220_COF_32Hz				0x5
+
 #define BMA220_ACCEL_CHANNEL(index, reg, axis) {			\
 	.type = IIO_ACCEL,						\
 	.address = reg,							\
 	.modified = 1,							\
 	.channel2 = IIO_MOD_##axis,					\
 	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),			\
-	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),		\
+	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |		\
+	    BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY),		\
+	.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE) |\
+	    BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY),		\
 	.scan_index = index,						\
 	.scan_type = {							\
 		.sign = 's',						\
@@ -123,6 +133,7 @@ static const int bma220_scale_table[][2] = {
 struct bma220_data {
 	struct regmap *regmap;
 	struct mutex lock;
+	u8 lpf_3dB_freq_idx;
 	u8 range_idx;
 	struct iio_trigger *trig;
 	struct {
@@ -139,6 +150,16 @@ static const struct iio_chan_spec bma220_channels[] = {
 	IIO_CHAN_SOFT_TIMESTAMP(3),
 };
 
+/* Available cut-off frequencies of the low pass filter in Hz. */
+static const int bma220_lpf_3dB_freq_Hz_table[] = {
+	[BMA220_COF_1000Hz] = 1000,
+	[BMA220_COF_500Hz] = 500,
+	[BMA220_COF_250Hz] = 250,
+	[BMA220_COF_125Hz] = 125,
+	[BMA220_COF_64Hz] = 64,
+	[BMA220_COF_32Hz] = 32,
+};
+
 static const unsigned long bma220_accel_scan_masks[] = {
 	BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z),
 	0
@@ -253,6 +274,10 @@ static int bma220_read_raw(struct iio_dev *indio_dev,
 		*val = bma220_scale_table[index][0];
 		*val2 = bma220_scale_table[index][1];
 		return IIO_VAL_INT_PLUS_MICRO;
+	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
+		index = data->lpf_3dB_freq_idx;
+		*val = bma220_lpf_3dB_freq_Hz_table[index];
+		return IIO_VAL_INT;
 	}
 
 	return -EINVAL;
@@ -271,6 +296,18 @@ static int bma220_find_match_2dt(const int (*tbl)[2], const int n,
 	return -EINVAL;
 }
 
+static int bma220_find_match(const int *arr, const int n, const int val)
+{
+	int i;
+
+	for (i = 0; i < n; i++) {
+		if (arr[i] == val)
+			return i;
+	}
+
+	return -EINVAL;
+}
+
 static int bma220_write_raw(struct iio_dev *indio_dev,
 			    struct iio_chan_spec const *chan,
 			    int val, int val2, long mask)
@@ -296,6 +333,21 @@ static int bma220_write_raw(struct iio_dev *indio_dev,
 			return ret;
 		data->range_idx = index;
 
+		return 0;
+	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
+		index = bma220_find_match(bma220_lpf_3dB_freq_Hz_table,
+					  ARRAY_SIZE(bma220_lpf_3dB_freq_Hz_table),
+					  val);
+		if (index < 0)
+			return -EINVAL;
+
+		ret = regmap_update_bits(data->regmap, BMA220_REG_FILTER,
+					 BMA220_FILTER_MASK,
+					 FIELD_PREP(BMA220_FILTER_MASK, index));
+		if (ret < 0)
+			return ret;
+		data->lpf_3dB_freq_idx = index;
+
 		return 0;
 	}
 
@@ -313,6 +365,11 @@ static int bma220_read_avail(struct iio_dev *indio_dev,
 		*type = IIO_VAL_INT_PLUS_MICRO;
 		*length = ARRAY_SIZE(bma220_scale_table) * 2;
 		return IIO_AVAIL_LIST;
+	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
+		*vals = (const int *)bma220_lpf_3dB_freq_Hz_table;
+		*type = IIO_VAL_INT;
+		*length = ARRAY_SIZE(bma220_lpf_3dB_freq_Hz_table);
+		return IIO_AVAIL_LIST;
 	default:
 		return -EINVAL;
 	}
Signature · 1 line
2.49.1
maintainer Applied
#37 lore raw

Re: [PATCH v4 17/19] iio: accel: bma220: add LPF cut-off frequency mapping

Quoted 4 lines · On Sun, 05 Oct 2025 16:12:26 +0300 Petre Rodan <[email protected]>…

Add mapping for the low pass filter cut-off frequency.
Make valid values visible for both the cut-off frequency and the scale.

Applied.

author maintainer
#38 lore raw

PATCH v4 18/19 iio: accel: bma220: add debugfs reg access

In reply to Petre Rodan

Allow read/write access to sensor registers for use in unit-tests.

---
v1->v4 no change

---
 drivers/iio/accel/bma220_core.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/iio/accel/bma220_core.c +11 -0
index 7109759e28397d2660f17707124a8803a254cb14..0d6c301b1c47a04cfca5bae157f8ce6144f0b854 100644
@@ -375,10 +375,21 @@ static int bma220_read_avail(struct iio_dev *indio_dev,
 	}
 }
 
+static int bma220_reg_access(struct iio_dev *indio_dev, unsigned int reg,
+			     unsigned int writeval, unsigned int *readval)
+{
+	struct bma220_data *data = iio_priv(indio_dev);
+
+	if (readval)
+		return regmap_read(data->regmap, reg, readval);
+	return regmap_write(data->regmap, reg, writeval);
+}
+
 static const struct iio_info bma220_info = {
 	.read_raw		= bma220_read_raw,
 	.write_raw		= bma220_write_raw,
 	.read_avail		= bma220_read_avail,
+	.debugfs_reg_access	= &bma220_reg_access,
 };
 
 static int bma220_reset(struct bma220_data *data, bool up)
Signature · 1 line
2.49.1
author maintainer
#40 lore raw

PATCH v4 19/19 iio: accel: bma220: add maintainer

In reply to Petre Rodan

Add maintainer for this driver.

---
v1->v4 no change

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index f090c2f6e63a0d255a025885cc4573f5802ef159..aaeb4ae6fd2282264da7e61b6fc32c00fc90a5ae 100644
@@ -4402,6 +4402,13 @@ F:	include/net/bond*
 F:	include/uapi/linux/if_bonding.h
 F:	tools/testing/selftests/drivers/net/bonding/
 
+BOSCH SENSORTEC BMA220 ACCELEROMETER IIO DRIVER
+M:	Petre Rodan <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/accel/bosch,bma220.yaml
+F:	drivers/iio/accel/bma220*
+
 BOSCH SENSORTEC BMA400 ACCELEROMETER IIO DRIVER
 M:	Dan Robertson <[email protected]>
 L:	[email protected]
Signature · 1 line
2.49.1
maintainer Applied
#41 lore raw

Re: [PATCH v4 19/19] iio: accel: bma220: add maintainer

Quoted 3 lines · On Sun, 05 Oct 2025 16:12:28 +0300 Petre Rodan <[email protected]>…

Add maintainer for this driver.

Applied. Thanks for stepping up to maintain this going forwards

Jonathan

Quoted 25 lines

---
v1->v4 no change

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index f090c2f6e63a0d255a025885cc4573f5802ef159..aaeb4ae6fd2282264da7e61b6fc32c00fc90a5ae 100644
@@ -4402,6 +4402,13 @@ F:	include/net/bond*
 F:	include/uapi/linux/if_bonding.h
 F:	tools/testing/selftests/drivers/net/bonding/
 
+BOSCH SENSORTEC BMA220 ACCELEROMETER IIO DRIVER
+M:	Petre Rodan <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/accel/bosch,bma220.yaml
+F:	drivers/iio/accel/bma220*
+
 BOSCH SENSORTEC BMA400 ACCELEROMETER IIO DRIVER
 M:	Dan Robertson <[email protected]>
 L:	[email protected]