* [PATCH v4 01/19] iio: accel: bma220: remove incorrect kernel-doc marking
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 14:21 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 02/19] iio: accel: bma220: relax constraints during probe() Petre Rodan
` (17 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
Remove incorrect use of kernel-doc marking.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v4 - split from bigger patch (Andy)
---
drivers/iio/accel/bma220_spi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
index 01592eebf05bb6b002d44c41cca1d2dd5f28350c..505ad70912571ba629f91e56a92898d8320e976f 100644
--- a/drivers/iio/accel/bma220_spi.c
+++ b/drivers/iio/accel/bma220_spi.c
@@ -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.
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 01/19] iio: accel: bma220: remove incorrect kernel-doc marking
2025-10-05 13:12 ` [PATCH v4 01/19] iio: accel: bma220: remove incorrect kernel-doc marking Petre Rodan
@ 2025-10-12 14:21 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 14:21 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:10 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Remove incorrect use of kernel-doc marking.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
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
> ---
> v4 - split from bigger patch (Andy)
> ---
> drivers/iio/accel/bma220_spi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
> index 01592eebf05bb6b002d44c41cca1d2dd5f28350c..505ad70912571ba629f91e56a92898d8320e976f 100644
> --- a/drivers/iio/accel/bma220_spi.c
> +++ b/drivers/iio/accel/bma220_spi.c
> @@ -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.
>
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 02/19] iio: accel: bma220: relax constraints during probe()
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
2025-10-05 13:12 ` [PATCH v4 01/19] iio: accel: bma220: remove incorrect kernel-doc marking Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 14:22 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 03/19] iio: accel: bma220: cleanup license string Petre Rodan
` (16 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
Do not return error if the chip id being read is not the expected one.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v4 - split from bigger patch (Jonathan)
---
drivers/iio/accel/bma220_spi.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
index 505ad70912571ba629f91e56a92898d8320e976f..02ee6b4d51c0816a88ac258f0e5107111ec2a2bc 100644
--- a/drivers/iio/accel/bma220_spi.c
+++ b/drivers/iio/accel/bma220_spi.c
@@ -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);
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 02/19] iio: accel: bma220: relax constraints during probe()
2025-10-05 13:12 ` [PATCH v4 02/19] iio: accel: bma220: relax constraints during probe() Petre Rodan
@ 2025-10-12 14:22 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 14:22 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:11 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Do not return error if the chip id being read is not the expected one.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Applied.
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 03/19] iio: accel: bma220: cleanup license string
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
2025-10-05 13:12 ` [PATCH v4 01/19] iio: accel: bma220: remove incorrect kernel-doc marking Petre Rodan
2025-10-05 13:12 ` [PATCH v4 02/19] iio: accel: bma220: relax constraints during probe() Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 14:22 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 04/19] iio: accel: bma220: shorten spi->dev calls Petre Rodan
` (15 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
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")
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v4 - split from bigger patch (Andy)
---
drivers/iio/accel/bma220_spi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
index 02ee6b4d51c0816a88ac258f0e5107111ec2a2bc..8c313debc1dff7f4bae7c165bc555ee190996291 100644
--- a/drivers/iio/accel/bma220_spi.c
+++ b/drivers/iio/accel/bma220_spi.c
@@ -332,4 +332,4 @@ module_spi_driver(bma220_driver);
MODULE_AUTHOR("Tiberiu Breana <tiberiu.a.breana@intel.com>");
MODULE_DESCRIPTION("BMA220 acceleration sensor driver");
-MODULE_LICENSE("GPL v2");
+MODULE_LICENSE("GPL");
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 03/19] iio: accel: bma220: cleanup license string
2025-10-05 13:12 ` [PATCH v4 03/19] iio: accel: bma220: cleanup license string Petre Rodan
@ 2025-10-12 14:22 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 14:22 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:12 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> 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")
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Applied.
> ---
> v4 - split from bigger patch (Andy)
> ---
> drivers/iio/accel/bma220_spi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
> index 02ee6b4d51c0816a88ac258f0e5107111ec2a2bc..8c313debc1dff7f4bae7c165bc555ee190996291 100644
> --- a/drivers/iio/accel/bma220_spi.c
> +++ b/drivers/iio/accel/bma220_spi.c
> @@ -332,4 +332,4 @@ module_spi_driver(bma220_driver);
>
> MODULE_AUTHOR("Tiberiu Breana <tiberiu.a.breana@intel.com>");
> MODULE_DESCRIPTION("BMA220 acceleration sensor driver");
> -MODULE_LICENSE("GPL v2");
> +MODULE_LICENSE("GPL");
>
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 04/19] iio: accel: bma220: shorten spi->dev calls
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (2 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 03/19] iio: accel: bma220: cleanup license string Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 14:23 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 05/19] iio: accel: bma220: move bma220_power function Petre Rodan
` (14 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
Provide functions easier access to device struct.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v4 - split from bigger patch (Andy)
---
drivers/iio/accel/bma220_spi.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
index 8c313debc1dff7f4bae7c165bc555ee190996291..a5d2906321ae5fc67c0e1dc44651833c5e7fcb39 100644
--- a/drivers/iio/accel/bma220_spi.c
+++ b/drivers/iio/accel/bma220_spi.c
@@ -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)
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 04/19] iio: accel: bma220: shorten spi->dev calls
2025-10-05 13:12 ` [PATCH v4 04/19] iio: accel: bma220: shorten spi->dev calls Petre Rodan
@ 2025-10-12 14:23 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 14:23 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:13 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Provide functions easier access to device struct.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Applied.
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 05/19] iio: accel: bma220: move bma220_power function
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (3 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 04/19] iio: accel: bma220: shorten spi->dev calls Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 14:24 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 06/19] iio: accel: bma220: cleanup includes Petre Rodan
` (13 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
Move bma220_power() before bma220_init() as a precursor to a
patch that removes code duplication.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v3->v4
- unsigned i (Andy)
---
drivers/iio/accel/bma220_spi.c | 49 +++++++++++++++++++++---------------------
1 file changed, 25 insertions(+), 24 deletions(-)
diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
index a5d2906321ae5fc67c0e1dc44651833c5e7fcb39..45ac0d7ee27de65b204bd2766f26024e4ed57f4c 100644
--- a/drivers/iio/accel/bma220_spi.c
+++ b/drivers/iio/accel/bma220_spi.c
@@ -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);
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 05/19] iio: accel: bma220: move bma220_power function
2025-10-05 13:12 ` [PATCH v4 05/19] iio: accel: bma220: move bma220_power function Petre Rodan
@ 2025-10-12 14:24 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 14:24 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:14 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Move bma220_power() before bma220_init() as a precursor to a
> patch that removes code duplication.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Applied.
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 06/19] iio: accel: bma220: cleanup includes
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (4 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 05/19] iio: accel: bma220: move bma220_power function Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 14:25 ` Jonathan Cameron
2025-10-12 14:34 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 07/19] iio: accel: bma220: split original driver Petre Rodan
` (12 subsequent siblings)
18 siblings, 2 replies; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
Tweak includes based on requirements.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v4 split from bigger patch (Andy)
---
drivers/iio/accel/bma220_spi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
index 45ac0d7ee27de65b204bd2766f26024e4ed57f4c..abff24a48e5aaa5efb05cdf1924ffea24f4da4c5 100644
--- a/drivers/iio/accel/bma220_spi.c
+++ b/drivers/iio/accel/bma220_spi.c
@@ -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>
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 06/19] iio: accel: bma220: cleanup includes
2025-10-05 13:12 ` [PATCH v4 06/19] iio: accel: bma220: cleanup includes Petre Rodan
@ 2025-10-12 14:25 ` Jonathan Cameron
2025-10-12 14:34 ` Jonathan Cameron
1 sibling, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 14:25 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:15 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Tweak includes based on requirements.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Applied.
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v4 06/19] iio: accel: bma220: cleanup includes
2025-10-05 13:12 ` [PATCH v4 06/19] iio: accel: bma220: cleanup includes Petre Rodan
2025-10-12 14:25 ` Jonathan Cameron
@ 2025-10-12 14:34 ` Jonathan Cameron
1 sibling, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 14:34 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:15 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Tweak includes based on requirements.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
see next patch. I tweaked this as below
> ---
> v4 split from bigger patch (Andy)
> ---
> drivers/iio/accel/bma220_spi.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
> index 45ac0d7ee27de65b204bd2766f26024e4ed57f4c..abff24a48e5aaa5efb05cdf1924ffea24f4da4c5 100644
> --- a/drivers/iio/accel/bma220_spi.c
> +++ b/drivers/iio/accel/bma220_spi.c
> @@ -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.
> -#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>
>
>
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 07/19] iio: accel: bma220: split original driver
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (5 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 06/19] iio: accel: bma220: cleanup includes Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 14:52 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 08/19] iio: accel: bma220: add open firmware table Petre Rodan
` (11 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
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.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
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(-)
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 8c3f7cf55d5fa432a4d4662b184a46cd59c3ebca..4648be329917a3054615ed324156d67f53baefb6 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -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"
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index ca8569e25aba31c3ae3437abf8506addbf5edffa..56a9f848f7f913633bc2a628c1ac5c9190774b9d 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -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
diff --git a/drivers/iio/accel/bma220.h b/drivers/iio/accel/bma220.h
new file mode 100644
index 0000000000000000000000000000000000000000..dea34244b4fc4971841dc60d79db6c7db27bea20
--- /dev/null
+++ b/drivers/iio/accel/bma220.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Forward declarations needed by the bma220 sources.
+ *
+ * Copyright 2025 Petre Rodan <petre.rodan@subdimension.ro>
+ */
+
+#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
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
new file mode 100644
index 0000000000000000000000000000000000000000..00fe1064486aa469f7ad15593027c7ec86197365
--- /dev/null
+++ b/drivers/iio/accel/bma220_core.c
@@ -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>
+#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, \
+ }, \
+}
+
+enum bma220_axis {
+ AXIS_X,
+ AXIS_Y,
+ AXIS_Z,
+};
+
+static const int bma220_scale_table[][2] = {
+ {0, 623000}, {1, 248000}, {2, 491000}, {4, 983000},
+};
+
+struct bma220_data {
+ struct spi_device *spi_device;
+ struct mutex lock;
+ struct {
+ s8 chans[3];
+ /* Ensure timestamp is naturally aligned. */
+ aligned_s64 timestamp;
+ } scan;
+ u8 tx_buf[2] __aligned(IIO_DMA_MINALIGN);
+};
+
+static const struct iio_chan_spec bma220_channels[] = {
+ BMA220_ACCEL_CHANNEL(0, BMA220_REG_ACCEL_X, X),
+ BMA220_ACCEL_CHANNEL(1, BMA220_REG_ACCEL_Y, Y),
+ BMA220_ACCEL_CHANNEL(2, BMA220_REG_ACCEL_Z, Z),
+ IIO_CHAN_SOFT_TIMESTAMP(3),
+};
+
+static inline int bma220_read_reg(struct spi_device *spi, u8 reg)
+{
+ return spi_w8r8(spi, reg | BMA220_READ_MASK);
+}
+
+static const unsigned long bma220_accel_scan_masks[] = {
+ BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z),
+ 0
+};
+
+static irqreturn_t bma220_trigger_handler(int irq, void *p)
+{
+ int ret;
+ struct iio_poll_func *pf = p;
+ struct iio_dev *indio_dev = pf->indio_dev;
+ struct bma220_data *data = iio_priv(indio_dev);
+ struct spi_device *spi = data->spi_device;
+
+ mutex_lock(&data->lock);
+ data->tx_buf[0] = BMA220_REG_ACCEL_X | BMA220_READ_MASK;
+ ret = spi_write_then_read(spi, data->tx_buf, 1, &data->scan.chans,
+ ARRAY_SIZE(bma220_channels) - 1);
+ if (ret < 0)
+ goto err;
+
+ iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan),
+ pf->timestamp);
+err:
+ mutex_unlock(&data->lock);
+ iio_trigger_notify_done(indio_dev->trig);
+
+ return IRQ_HANDLED;
+}
+
+static int bma220_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int *val, int *val2, long mask)
+{
+ int ret;
+ u8 range_idx;
+ struct bma220_data *data = iio_priv(indio_dev);
+
+ switch (mask) {
+ case IIO_CHAN_INFO_RAW:
+ ret = bma220_read_reg(data->spi_device, chan->address);
+ if (ret < 0)
+ return -EINVAL;
+ *val = sign_extend32(ret >> chan->scan_type.shift,
+ chan->scan_type.realbits - 1);
+ return IIO_VAL_INT;
+ case IIO_CHAN_INFO_SCALE:
+ ret = bma220_read_reg(data->spi_device, BMA220_REG_RANGE);
+ if (ret < 0)
+ return ret;
+ range_idx = ret & BMA220_RANGE_MASK;
+ *val = bma220_scale_table[range_idx][0];
+ *val2 = bma220_scale_table[range_idx][1];
+ return IIO_VAL_INT_PLUS_MICRO;
+ }
+
+ 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);
+
+ 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;
+ }
+ if (index < 0)
+ return -EINVAL;
+
+ mutex_lock(&data->lock);
+ data->tx_buf[0] = BMA220_REG_RANGE;
+ data->tx_buf[1] = index;
+ ret = spi_write(data->spi_device, data->tx_buf,
+ sizeof(data->tx_buf));
+ if (ret < 0)
+ return ret;
+ mutex_unlock(&data->lock);
+
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
+static int bma220_read_avail(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ const int **vals, int *type, int *length,
+ long mask)
+{
+ switch (mask) {
+ case IIO_CHAN_INFO_SCALE:
+ *vals = (int *)bma220_scale_table;
+ *type = IIO_VAL_INT_PLUS_MICRO;
+ *length = ARRAY_SIZE(bma220_scale_table) * 2;
+ return IIO_AVAIL_LIST;
+ default:
+ return -EINVAL;
+ }
+}
+
+static const struct iio_info bma220_info = {
+ .read_raw = bma220_read_raw,
+ .write_raw = bma220_write_raw,
+ .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;
+ 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)
+ 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;
+
+ return 0;
+}
+
+static void bma220_deinit(void *spi)
+{
+ bma220_power(spi, false);
+}
+
+int bma220_common_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(dev, sizeof(*data));
+ if (!indio_dev)
+ return -ENOMEM;
+
+ data = iio_priv(indio_dev);
+ data->spi_device = spi;
+ mutex_init(&data->lock);
+
+ indio_dev->info = &bma220_info;
+ indio_dev->name = BMA220_DEVICE_NAME;
+ indio_dev->modes = INDIO_DIRECT_MODE;
+ indio_dev->channels = bma220_channels;
+ indio_dev->num_channels = ARRAY_SIZE(bma220_channels);
+ indio_dev->available_scan_masks = bma220_accel_scan_masks;
+
+ ret = bma220_init(data->spi_device);
+ if (ret)
+ return ret;
+
+ ret = devm_add_action_or_reset(dev, bma220_deinit, spi);
+ if (ret)
+ return ret;
+
+ ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+ iio_pollfunc_store_time,
+ bma220_trigger_handler, NULL);
+ if (ret < 0) {
+ dev_err(dev, "iio triggered buffer setup failed\n");
+ return ret;
+ }
+
+ return devm_iio_device_register(dev, indio_dev);
+}
+EXPORT_SYMBOL_NS(bma220_common_probe, "IIO_BOSCH_BMA220");
+
+static int bma220_suspend(struct device *dev)
+{
+ struct spi_device *spi = to_spi_device(dev);
+
+ return bma220_power(spi, false);
+}
+
+static int bma220_resume(struct device *dev)
+{
+ struct spi_device *spi = to_spi_device(dev);
+
+ return bma220_power(spi, true);
+}
+EXPORT_NS_SIMPLE_DEV_PM_OPS(bma220_pm_ops, bma220_suspend, bma220_resume,
+ IIO_BOSCH_BMA220);
+
+MODULE_AUTHOR("Tiberiu Breana <tiberiu.a.breana@intel.com>");
+MODULE_DESCRIPTION("BMA220 acceleration sensor driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
index abff24a48e5aaa5efb05cdf1924ffea24f4da4c5..70b8bd94895e95936c7294271b5d46d9ec9903c6 100644
--- a/drivers/iio/accel/bma220_spi.c
+++ b/drivers/iio/accel/bma220_spi.c
@@ -5,334 +5,42 @@
* Copyright (c) 2016,2020 Intel Corporation.
*/
-#include <linux/bits.h>
+#include <linux/errno.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>
-#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, \
- }, \
-}
-
-enum bma220_axis {
- AXIS_X,
- AXIS_Y,
- AXIS_Z,
-};
-
-static const int bma220_scale_table[][2] = {
- {0, 623000}, {1, 248000}, {2, 491000}, {4, 983000},
-};
-
-struct bma220_data {
- struct spi_device *spi_device;
- struct mutex lock;
- struct {
- s8 chans[3];
- /* Ensure timestamp is naturally aligned. */
- aligned_s64 timestamp;
- } scan;
- u8 tx_buf[2] __aligned(IIO_DMA_MINALIGN);
-};
-
-static const struct iio_chan_spec bma220_channels[] = {
- BMA220_ACCEL_CHANNEL(0, BMA220_REG_ACCEL_X, X),
- BMA220_ACCEL_CHANNEL(1, BMA220_REG_ACCEL_Y, Y),
- BMA220_ACCEL_CHANNEL(2, BMA220_REG_ACCEL_Z, Z),
- IIO_CHAN_SOFT_TIMESTAMP(3),
-};
-
-static inline int bma220_read_reg(struct spi_device *spi, u8 reg)
+static int bma220_spi_probe(struct spi_device *spi)
{
- return spi_w8r8(spi, reg | BMA220_READ_MASK);
-}
-
-static const unsigned long bma220_accel_scan_masks[] = {
- BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z),
- 0
-};
-
-static irqreturn_t bma220_trigger_handler(int irq, void *p)
-{
- int ret;
- struct iio_poll_func *pf = p;
- struct iio_dev *indio_dev = pf->indio_dev;
- struct bma220_data *data = iio_priv(indio_dev);
- struct spi_device *spi = data->spi_device;
-
- mutex_lock(&data->lock);
- data->tx_buf[0] = BMA220_REG_ACCEL_X | BMA220_READ_MASK;
- ret = spi_write_then_read(spi, data->tx_buf, 1, &data->scan.chans,
- ARRAY_SIZE(bma220_channels) - 1);
- if (ret < 0)
- goto err;
-
- iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan),
- pf->timestamp);
-err:
- mutex_unlock(&data->lock);
- iio_trigger_notify_done(indio_dev->trig);
-
- return IRQ_HANDLED;
-}
-
-static int bma220_read_raw(struct iio_dev *indio_dev,
- struct iio_chan_spec const *chan,
- int *val, int *val2, long mask)
-{
- int ret;
- u8 range_idx;
- struct bma220_data *data = iio_priv(indio_dev);
-
- switch (mask) {
- case IIO_CHAN_INFO_RAW:
- ret = bma220_read_reg(data->spi_device, chan->address);
- if (ret < 0)
- return -EINVAL;
- *val = sign_extend32(ret >> chan->scan_type.shift,
- chan->scan_type.realbits - 1);
- return IIO_VAL_INT;
- case IIO_CHAN_INFO_SCALE:
- ret = bma220_read_reg(data->spi_device, BMA220_REG_RANGE);
- if (ret < 0)
- return ret;
- range_idx = ret & BMA220_RANGE_MASK;
- *val = bma220_scale_table[range_idx][0];
- *val2 = bma220_scale_table[range_idx][1];
- return IIO_VAL_INT_PLUS_MICRO;
- }
-
- 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);
-
- 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;
- }
- if (index < 0)
- return -EINVAL;
-
- mutex_lock(&data->lock);
- data->tx_buf[0] = BMA220_REG_RANGE;
- data->tx_buf[1] = index;
- ret = spi_write(data->spi_device, data->tx_buf,
- sizeof(data->tx_buf));
- if (ret < 0)
- dev_err(&data->spi_device->dev,
- "failed to set measurement range\n");
- mutex_unlock(&data->lock);
-
- return 0;
- }
-
- return -EINVAL;
-}
-
-static int bma220_read_avail(struct iio_dev *indio_dev,
- struct iio_chan_spec const *chan,
- const int **vals, int *type, int *length,
- long mask)
-{
- switch (mask) {
- case IIO_CHAN_INFO_SCALE:
- *vals = (int *)bma220_scale_table;
- *type = IIO_VAL_INT_PLUS_MICRO;
- *length = ARRAY_SIZE(bma220_scale_table) * 2;
- return IIO_AVAIL_LIST;
- default:
- return -EINVAL;
- }
-}
-
-static const struct iio_info bma220_info = {
- .read_raw = bma220_read_raw,
- .write_raw = bma220_write_raw,
- .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;
- 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)
- 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;
-
- return 0;
-}
-
-static void bma220_deinit(void *spi)
-{
- bma220_power(spi, false);
-}
-
-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(dev, sizeof(*data));
- if (!indio_dev)
- return -ENOMEM;
-
- data = iio_priv(indio_dev);
- data->spi_device = spi;
- mutex_init(&data->lock);
-
- indio_dev->info = &bma220_info;
- indio_dev->name = BMA220_DEVICE_NAME;
- indio_dev->modes = INDIO_DIRECT_MODE;
- indio_dev->channels = bma220_channels;
- indio_dev->num_channels = ARRAY_SIZE(bma220_channels);
- indio_dev->available_scan_masks = bma220_accel_scan_masks;
-
- ret = bma220_init(data->spi_device);
- if (ret)
- return ret;
-
- ret = devm_add_action_or_reset(dev, bma220_deinit, spi);
- if (ret)
- return ret;
-
- ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
- iio_pollfunc_store_time,
- bma220_trigger_handler, NULL);
- if (ret < 0) {
- dev_err(dev, "iio triggered buffer setup failed\n");
- return ret;
- }
-
- return devm_iio_device_register(dev, indio_dev);
-}
-
-static int bma220_suspend(struct device *dev)
-{
- struct spi_device *spi = to_spi_device(dev);
-
- return bma220_power(spi, false);
-}
-
-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 },
{ }
};
static const struct acpi_device_id bma220_acpi_id[] = {
- {"BMA0220", 0},
+ { "BMA0220", 0 },
{ }
};
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 <tiberiu.a.breana@intel.com>");
-MODULE_DESCRIPTION("BMA220 acceleration sensor driver");
+MODULE_DESCRIPTION("BMA220 triaxial acceleration sensor spi driver");
MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("IIO_BOSCH_BMA220");
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 07/19] iio: accel: bma220: split original driver
2025-10-05 13:12 ` [PATCH v4 07/19] iio: accel: bma220: split original driver Petre Rodan
@ 2025-10-12 14:52 ` Jonathan Cameron
2025-10-14 16:52 ` Petre Rodan
0 siblings, 1 reply; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 14:52 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:16 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> 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.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
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
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index 00fe1064486a..050282f20d90 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -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>
diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
index 70b8bd94895e..761f475a5942 100644
--- a/drivers/iio/accel/bma220_spi.c
+++ b/drivers/iio/accel/bma220_spi.c
@@ -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);
> ---
> 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(-)
> diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..00fe1064486aa469f7ad15593027c7ec86197365
> --- /dev/null
> +++ b/drivers/iio/accel/bma220_core.c
> @@ -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.
> +#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, \
> + }, \
> +}
> +
> +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.
> +};
> diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
> index abff24a48e5aaa5efb05cdf1924ffea24f4da4c5..70b8bd94895e95936c7294271b5d46d9ec9903c6 100644
> --- a/drivers/iio/accel/bma220_spi.c
> +++ b/drivers/iio/accel/bma220_spi.c
> @@ -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.
> #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"
...
> -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!
> { }
> };
>
> static const struct acpi_device_id bma220_acpi_id[] = {
> - {"BMA0220", 0},
> + { "BMA0220", 0 },
Same here.
> { }
> };
> 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 <tiberiu.a.breana@intel.com>");
> -MODULE_DESCRIPTION("BMA220 acceleration sensor driver");
> +MODULE_DESCRIPTION("BMA220 triaxial acceleration sensor spi driver");
> MODULE_LICENSE("GPL");
> +MODULE_IMPORT_NS("IIO_BOSCH_BMA220");
>
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 07/19] iio: accel: bma220: split original driver
2025-10-12 14:52 ` Jonathan Cameron
@ 2025-10-14 16:52 ` Petre Rodan
0 siblings, 0 replies; 42+ messages in thread
From: Petre Rodan @ 2025-10-14 16:52 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno S??, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 978 bytes --]
Hi Jonathan,
On Sun, Oct 12, 2025 at 03:52:01PM +0100, Jonathan Cameron wrote:
> On Sun, 05 Oct 2025 16:12:16 +0300
> Petre Rodan <petre.rodan@subdimension.ro> wrote:
>
> > 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.
> >
> > Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
>
> 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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 08/19] iio: accel: bma220: add open firmware table
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (6 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 07/19] iio: accel: bma220: split original driver Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 14:54 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 09/19] iio: accel: bma220: turn power supplies on Petre Rodan
` (10 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
Add open firmware entry to the spi driver.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v1->v2 split from bigger patch
v3->v4 no change
---
drivers/iio/accel/bma220_spi.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
index 70b8bd94895e95936c7294271b5d46d9ec9903c6..b27592591d2817e2c3f3780f4307e3a76c7e06cb 100644
--- a/drivers/iio/accel/bma220_spi.c
+++ b/drivers/iio/accel/bma220_spi.c
@@ -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,
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 08/19] iio: accel: bma220: add open firmware table
2025-10-05 13:12 ` [PATCH v4 08/19] iio: accel: bma220: add open firmware table Petre Rodan
@ 2025-10-12 14:54 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 14:54 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:17 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Add open firmware entry to the spi driver.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
> ---
Applied. Thanks!
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 09/19] iio: accel: bma220: turn power supplies on
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (7 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 08/19] iio: accel: bma220: add open firmware table Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 14:55 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 10/19] iio: accel: bma220: reset registers during init stage Petre Rodan
` (9 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
Add devm_regulator_bulk_get_enable() to device probe().
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
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(+)
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index 00fe1064486aa469f7ad15593027c7ec86197365..319a3d6867ee5ac2da64c9baf02a760865302ee8 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -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)
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 09/19] iio: accel: bma220: turn power supplies on
2025-10-05 13:12 ` [PATCH v4 09/19] iio: accel: bma220: turn power supplies on Petre Rodan
@ 2025-10-12 14:55 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 14:55 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:18 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Add devm_regulator_bulk_get_enable() to device probe().
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Applied. Thanks!
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 10/19] iio: accel: bma220: reset registers during init stage
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (8 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 09/19] iio: accel: bma220: turn power supplies on Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 14:56 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 11/19] iio: accel: bma220: migrate to regmap API Petre Rodan
` (8 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
Bring all configuration registers to default values during
device probe().
Remove trivial code duplication regarding bma220_power() in
_init()
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v4 dev ptr (Andy)
---
drivers/iio/accel/bma220_core.c | 44 +++++++++++++++++++++++++++++++++--------
1 file changed, 36 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index 319a3d6867ee5ac2da64c9baf02a760865302ee8..1b118a9fce3f16f0cd805a68b9887c6eaf24973a 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -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;
}
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 10/19] iio: accel: bma220: reset registers during init stage
2025-10-05 13:12 ` [PATCH v4 10/19] iio: accel: bma220: reset registers during init stage Petre Rodan
@ 2025-10-12 14:56 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 14:56 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:19 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Bring all configuration registers to default values during
> device probe().
> Remove trivial code duplication regarding bma220_power() in
> _init()
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Applied.
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 11/19] iio: accel: bma220: migrate to regmap API
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (9 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 10/19] iio: accel: bma220: reset registers during init stage Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 15:04 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 12/19] iio: accel: bma220: populate buffer ts in trigger handler Petre Rodan
` (7 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
Switch to regmap API.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
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(-)
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 4648be329917a3054615ed324156d67f53baefb6..988fe4b1f9a52c2e671ea30d8590f25ee1685ac7 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -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
diff --git a/drivers/iio/accel/bma220.h b/drivers/iio/accel/bma220.h
index dea34244b4fc4971841dc60d79db6c7db27bea20..695f491bc5a03008f26fe8602ba633456159fb1d 100644
--- a/drivers/iio/accel/bma220.h
+++ b/drivers/iio/accel/bma220.h
@@ -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
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index 1b118a9fce3f16f0cd805a68b9887c6eaf24973a..7b1e87c6932a3a6698651e528fb8182c03a2432e 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -3,16 +3,20 @@
* BMA220 Digital triaxial acceleration sensor driver
*
* Copyright (c) 2016,2020 Intel Corporation.
+ * Copyright (c) 2025 Petre Rodan <petre.rodan@subdimension.ro>
*/
#include <linux/bits.h>
+#include <linux/bitfield.h>
+#include <linux/cleanup.h>
+#include <linux/device.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/pm.h>
+#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/types.h>
-#include <linux/spi/spi.h>
#include <linux/iio/buffer.h>
#include <linux/iio/iio.h>
@@ -23,16 +27,63 @@
#include "bma220.h"
#define BMA220_REG_ID 0x00
+#define BMA220_REG_REVISION_ID 0x01
#define BMA220_REG_ACCEL_X 0x02
#define BMA220_REG_ACCEL_Y 0x03
#define BMA220_REG_ACCEL_Z 0x04
+#define BMA220_REG_CONF0 0x05
+#define BMA220_HIGH_DUR_MSK GENMASK(5, 0)
+#define BMA220_HIGH_HY_MSK GENMASK(7, 6)
+#define BMA220_REG_CONF1 0x06
+#define BMA220_HIGH_TH_MSK GENMASK(3, 0)
+#define BMA220_LOW_TH_MSK GENMASK(7, 4)
+#define BMA220_REG_CONF2 0x07
+#define BMA220_LOW_DUR_MSK GENMASK(5, 0)
+#define BMA220_LOW_HY_MSK GENMASK(7, 6)
+#define BMA220_REG_CONF3 0x08
+#define BMA220_TT_DUR_MSK GENMASK(2, 0)
+#define BMA220_TT_TH_MSK GENMASK(6, 3)
+#define BMA220_REG_CONF4 0x09
+#define BMA220_SLOPE_DUR_MSK GENMASK(1, 0)
+#define BMA220_SLOPE_TH_MSK GENMASK(5, 2)
+#define BMA220_REG_CONF5 0x0a
+#define BMA220_TIP_EN_MSK BIT(4)
+#define BMA220_REG_IF0 0x0b
+#define BMA220_REG_IF1 0x0c
+#define BMA220_IF_SLOPE BIT(0)
+#define BMA220_IF_DRDY BIT(1)
+#define BMA220_IF_HIGH BIT(2)
+#define BMA220_IF_LOW BIT(3)
+#define BMA220_IF_TT BIT(4)
+#define BMA220_REG_IE0 0x0d
+#define BMA220_INT_EN_TAP_Z_MSK BIT(0)
+#define BMA220_INT_EN_TAP_Y_MSK BIT(1)
+#define BMA220_INT_EN_TAP_X_MSK BIT(2)
+#define BMA220_INT_EN_SLOPE_Z_MSK BIT(3)
+#define BMA220_INT_EN_SLOPE_Y_MSK BIT(4)
+#define BMA220_INT_EN_SLOPE_X_MSK BIT(5)
+#define BMA220_INT_EN_DRDY_MSK BIT(7)
+#define BMA220_REG_IE1 0x0e
+#define BMA220_INT_EN_HIGH_Z_MSK BIT(0)
+#define BMA220_INT_EN_HIGH_Y_MSK BIT(1)
+#define BMA220_INT_EN_HIGH_X_MSK BIT(2)
+#define BMA220_INT_EN_LOW_MSK BIT(3)
+#define BMA220_INT_LATCH_MSK GENMASK(6, 4)
+#define BMA220_INT_RST_MSK BIT(7)
+#define BMA220_REG_IE2 0x0f
+#define BMA220_REG_FILTER 0x10
+#define BMA220_FILTER_MASK GENMASK(3, 0)
#define BMA220_REG_RANGE 0x11
+#define BMA220_RANGE_MASK GENMASK(1, 0)
+#define BMA220_REG_WDT 0x17
+#define BMA220_WDT_MASK GENMASK(2, 1)
+#define BMA220_WDT_OFF 0x0
+#define BMA220_WDT_1MS 0x2
+#define BMA220_WDT_10MS 0x3
#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
@@ -68,14 +119,14 @@ static const int bma220_scale_table[][2] = {
};
struct bma220_data {
- struct spi_device *spi_device;
+ struct regmap *regmap;
struct mutex lock;
+ u8 range_idx;
struct {
s8 chans[3];
/* Ensure timestamp is naturally aligned. */
aligned_s64 timestamp;
- } scan;
- u8 tx_buf[2] __aligned(IIO_DMA_MINALIGN);
+ } scan __aligned(IIO_DMA_MINALIGN);
};
static const struct iio_chan_spec bma220_channels[] = {
@@ -85,35 +136,57 @@ static const struct iio_chan_spec bma220_channels[] = {
IIO_CHAN_SOFT_TIMESTAMP(3),
};
-static inline int bma220_read_reg(struct spi_device *spi, u8 reg)
-{
- return spi_w8r8(spi, reg | BMA220_READ_MASK);
-}
-
static const unsigned long bma220_accel_scan_masks[] = {
BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z),
0
};
+static bool bma220_is_writable_reg(struct device *dev, unsigned int reg)
+{
+ switch (reg) {
+ case BMA220_REG_CONF0:
+ case BMA220_REG_CONF1:
+ case BMA220_REG_CONF2:
+ case BMA220_REG_CONF3:
+ case BMA220_REG_CONF4:
+ case BMA220_REG_CONF5:
+ case BMA220_REG_IE0:
+ case BMA220_REG_IE1:
+ case BMA220_REG_IE2:
+ case BMA220_REG_FILTER:
+ case BMA220_REG_RANGE:
+ case BMA220_REG_WDT:
+ return true;
+ default:
+ return false;
+ }
+}
+
+const struct regmap_config bma220_spi_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .read_flag_mask = BIT(7),
+ .max_register = BMA220_REG_SOFTRESET,
+ .cache_type = REGCACHE_NONE,
+ .writeable_reg = bma220_is_writable_reg,
+};
+EXPORT_SYMBOL_NS_GPL(bma220_spi_regmap_config, "IIO_BOSCH_BMA220");
+
static irqreturn_t bma220_trigger_handler(int irq, void *p)
{
int ret;
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
struct bma220_data *data = iio_priv(indio_dev);
- struct spi_device *spi = data->spi_device;
- mutex_lock(&data->lock);
- data->tx_buf[0] = BMA220_REG_ACCEL_X | BMA220_READ_MASK;
- ret = spi_write_then_read(spi, data->tx_buf, 1, &data->scan.chans,
- ARRAY_SIZE(bma220_channels) - 1);
+ ret = regmap_bulk_read(data->regmap, BMA220_REG_ACCEL_X,
+ &data->scan.chans,
+ sizeof(data->scan.chans));
if (ret < 0)
- goto err;
+ return IRQ_NONE;
iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan),
pf->timestamp);
-err:
- mutex_unlock(&data->lock);
iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
@@ -124,24 +197,24 @@ static int bma220_read_raw(struct iio_dev *indio_dev,
int *val, int *val2, long mask)
{
int ret;
- u8 range_idx;
+ u8 index;
+ unsigned int reg;
struct bma220_data *data = iio_priv(indio_dev);
+ guard(mutex)(&data->lock);
+
switch (mask) {
case IIO_CHAN_INFO_RAW:
- ret = bma220_read_reg(data->spi_device, chan->address);
+ ret = regmap_read(data->regmap, chan->address, ®);
if (ret < 0)
return -EINVAL;
- *val = sign_extend32(ret >> chan->scan_type.shift,
+ *val = sign_extend32(reg >> chan->scan_type.shift,
chan->scan_type.realbits - 1);
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
- ret = bma220_read_reg(data->spi_device, BMA220_REG_RANGE);
- if (ret < 0)
- return ret;
- range_idx = ret & BMA220_RANGE_MASK;
- *val = bma220_scale_table[range_idx][0];
- *val2 = bma220_scale_table[range_idx][1];
+ index = data->range_idx;
+ *val = bma220_scale_table[index][0];
+ *val2 = bma220_scale_table[index][1];
return IIO_VAL_INT_PLUS_MICRO;
}
@@ -157,6 +230,8 @@ static int bma220_write_raw(struct iio_dev *indio_dev,
int index = -1;
struct bma220_data *data = iio_priv(indio_dev);
+ guard(mutex)(&data->lock);
+
switch (mask) {
case IIO_CHAN_INFO_SCALE:
for (i = 0; i < ARRAY_SIZE(bma220_scale_table); i++)
@@ -168,14 +243,12 @@ static int bma220_write_raw(struct iio_dev *indio_dev,
if (index < 0)
return -EINVAL;
- mutex_lock(&data->lock);
- data->tx_buf[0] = BMA220_REG_RANGE;
- data->tx_buf[1] = index;
- ret = spi_write(data->spi_device, data->tx_buf,
- sizeof(data->tx_buf));
+ ret = regmap_update_bits(data->regmap, BMA220_REG_RANGE,
+ BMA220_RANGE_MASK,
+ FIELD_PREP(BMA220_RANGE_MASK, index));
if (ret < 0)
return ret;
- mutex_unlock(&data->lock);
+ data->range_idx = index;
return 0;
}
@@ -205,10 +278,10 @@ static const struct iio_info bma220_info = {
.read_avail = bma220_read_avail,
};
-static int bma220_reset(struct spi_device *spi, bool up)
+static int bma220_reset(struct bma220_data *data, bool up)
{
int ret;
- unsigned int i;
+ unsigned int i, val;
/*
* The chip can be reset by a simple register read.
@@ -216,24 +289,24 @@ static int bma220_reset(struct spi_device *spi, bool up)
* 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);
+ ret = regmap_read(data->regmap, BMA220_REG_SOFTRESET, &val);
if (ret < 0)
return ret;
- if (up && ret == BMA220_RESET_MODE)
+ if (up && val == BMA220_RESET_MODE)
return 0;
- if (!up && ret == BMA220_NONRESET_MODE)
+ if (!up && val == BMA220_NONRESET_MODE)
return 0;
}
return -EBUSY;
}
-static int bma220_power(struct spi_device *spi, bool up)
+static int bma220_power(struct bma220_data *data, bool up)
{
int ret;
- unsigned int i;
+ unsigned int i, val;
/*
* The chip can be suspended/woken up by a simple register read.
@@ -241,70 +314,84 @@ static int bma220_power(struct spi_device *spi, bool up)
* 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);
+ ret = regmap_read(data->regmap, BMA220_REG_SUSPEND, &val);
if (ret < 0)
return ret;
- if (up && ret == BMA220_SUSPEND_SLEEP)
+ if (up && val == BMA220_SUSPEND_SLEEP)
return 0;
- if (!up && ret == BMA220_SUSPEND_WAKE)
+ if (!up && val == BMA220_SUSPEND_WAKE)
return 0;
}
return -EBUSY;
}
-static int bma220_init(struct spi_device *spi)
+static int bma220_init(struct device *dev, struct bma220_data *data)
{
int ret;
- struct device *dev = &spi->dev;
+ unsigned int val;
static const char * const regulator_names[] = { "vddd", "vddio", "vdda" };
- ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names),
+ 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)
+ ret = regmap_read(data->regmap, BMA220_REG_ID, &val);
+ if (ret)
return dev_err_probe(dev, ret,
"Failed to read chip id register\n");
- if (ret != BMA220_CHIP_ID)
- dev_info(dev, "Unknown chip found: 0x%02x\n", ret);
+ if (val != BMA220_CHIP_ID)
+ dev_info(dev, "Unknown chip found: 0x%02x\n", val);
- /* Make sure the chip is powered on and config registers are reset */
- ret = bma220_power(spi, true);
+ ret = bma220_power(data, true);
if (ret)
return dev_err_probe(dev, ret, "Failed to power-on chip\n");
- ret = bma220_reset(spi, true);
+ ret = bma220_reset(data, true);
if (ret)
return dev_err_probe(dev, ret, "Failed to soft reset chip\n");
return 0;
}
-static void bma220_deinit(void *spi)
+static void bma220_deinit(void *data_ptr)
{
- bma220_power(spi, false);
+ struct bma220_data *data = data_ptr;
+ int ret;
+ struct device *dev = regmap_get_device(data->regmap);
+
+ ret = bma220_power(data, false);
+ if (ret)
+ dev_warn(dev,
+ "Failed to put device into suspend mode (%pe)\n",
+ ERR_PTR(ret));
}
-int bma220_common_probe(struct spi_device *spi)
+int bma220_common_probe(struct device *dev, struct regmap *regmap, int irq)
{
int ret;
struct iio_dev *indio_dev;
struct bma220_data *data;
- struct device *dev = &spi->dev;
indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
if (!indio_dev)
return -ENOMEM;
data = iio_priv(indio_dev);
- data->spi_device = spi;
- mutex_init(&data->lock);
+ data->regmap = regmap;
+
+ ret = bma220_init(dev, data);
+ if (ret)
+ return ret;
+
+ ret = devm_mutex_init(dev, &data->lock);
+ if (ret)
+ return ret;
indio_dev->info = &bma220_info;
indio_dev->name = BMA220_DEVICE_NAME;
@@ -313,38 +400,34 @@ int bma220_common_probe(struct spi_device *spi)
indio_dev->num_channels = ARRAY_SIZE(bma220_channels);
indio_dev->available_scan_masks = bma220_accel_scan_masks;
- ret = bma220_init(data->spi_device);
- if (ret)
- return ret;
-
- ret = devm_add_action_or_reset(dev, bma220_deinit, spi);
+ ret = devm_add_action_or_reset(dev, bma220_deinit, data);
if (ret)
return ret;
ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
iio_pollfunc_store_time,
bma220_trigger_handler, NULL);
- if (ret < 0) {
- dev_err(dev, "iio triggered buffer setup failed\n");
- return ret;
- }
+ if (ret < 0)
+ dev_err_probe(dev, ret, "iio triggered buffer setup failed\n");
return devm_iio_device_register(dev, indio_dev);
}
-EXPORT_SYMBOL_NS(bma220_common_probe, "IIO_BOSCH_BMA220");
+EXPORT_SYMBOL_NS_GPL(bma220_common_probe, "IIO_BOSCH_BMA220");
static int bma220_suspend(struct device *dev)
{
- struct spi_device *spi = to_spi_device(dev);
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct bma220_data *data = iio_priv(indio_dev);
- return bma220_power(spi, false);
+ return bma220_power(data, false);
}
static int bma220_resume(struct device *dev)
{
- struct spi_device *spi = to_spi_device(dev);
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct bma220_data *data = iio_priv(indio_dev);
- return bma220_power(spi, true);
+ return bma220_power(data, true);
}
EXPORT_NS_SIMPLE_DEV_PM_OPS(bma220_pm_ops, bma220_suspend, bma220_resume,
IIO_BOSCH_BMA220);
diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
index b27592591d2817e2c3f3780f4307e3a76c7e06cb..8990155ac0cd36ace08d1192b4dda3c275ad675e 100644
--- a/drivers/iio/accel/bma220_spi.c
+++ b/drivers/iio/accel/bma220_spi.c
@@ -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[] = {
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 11/19] iio: accel: bma220: migrate to regmap API
2025-10-05 13:12 ` [PATCH v4 11/19] iio: accel: bma220: migrate to regmap API Petre Rodan
@ 2025-10-12 15:04 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 15:04 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:20 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Switch to regmap API.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
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
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 12/19] iio: accel: bma220: populate buffer ts in trigger handler
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (10 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 11/19] iio: accel: bma220: migrate to regmap API Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 15:06 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 13/19] iio: accel: bma220: use find_match_table fct Petre Rodan
` (6 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
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.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
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(-)
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index 7b1e87c6932a3a6698651e528fb8182c03a2432e..ec7409db83f81882043653cd70e3205500348994 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -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");
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 12/19] iio: accel: bma220: populate buffer ts in trigger handler
2025-10-05 13:12 ` [PATCH v4 12/19] iio: accel: bma220: populate buffer ts in trigger handler Petre Rodan
@ 2025-10-12 15:06 ` Jonathan Cameron
2025-10-12 20:54 ` Petre Rodan
0 siblings, 1 reply; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 15:06 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:21 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> 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.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
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.
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v4 12/19] iio: accel: bma220: populate buffer ts in trigger handler
2025-10-12 15:06 ` Jonathan Cameron
@ 2025-10-12 20:54 ` Petre Rodan
0 siblings, 0 replies; 42+ messages in thread
From: Petre Rodan @ 2025-10-12 20:54 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 505 bytes --]
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.
> 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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 13/19] iio: accel: bma220: use find_match_table fct
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (11 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 12/19] iio: accel: bma220: populate buffer ts in trigger handler Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 15:20 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 14/19] iio: accel: bma220: add i2c module Petre Rodan
` (5 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
Clean up the code a bit by using a find_match_table function.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
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(-)
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index ec7409db83f81882043653cd70e3205500348994..42d5acce0a8387734d932c77fec9777a7a01f774 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -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;
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 13/19] iio: accel: bma220: use find_match_table fct
2025-10-05 13:12 ` [PATCH v4 13/19] iio: accel: bma220: use find_match_table fct Petre Rodan
@ 2025-10-12 15:20 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 15:20 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:22 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Clean up the code a bit by using a find_match_table function.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Applied. Thanks!
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 14/19] iio: accel: bma220: add i2c module
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (12 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 13/19] iio: accel: bma220: use find_match_table fct Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 15:17 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 15/19] iio: accel: bma220: add i2c watchdog feature Petre Rodan
` (4 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
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.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
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(-)
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 988fe4b1f9a52c2e671ea30d8590f25ee1685ac7..76911278fb217bd3e429c427b873fb7eae26420e 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -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
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index 56a9f848f7f913633bc2a628c1ac5c9190774b9d..fa440a85928398fee927081f605595ba9fbc4ad9 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -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
diff --git a/drivers/iio/accel/bma220.h b/drivers/iio/accel/bma220.h
index 695f491bc5a03008f26fe8602ba633456159fb1d..e53ca63de54b4e81df0908b11d0fb7f03a86dbdc 100644
--- a/drivers/iio/accel/bma220.h
+++ b/drivers/iio/accel/bma220.h
@@ -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;
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index 42d5acce0a8387734d932c77fec9777a7a01f774..a3faf1f5ec6d79f2c6105697b404d6eb1f4501db 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -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;
diff --git a/drivers/iio/accel/bma220_i2c.c b/drivers/iio/accel/bma220_i2c.c
new file mode 100644
index 0000000000000000000000000000000000000000..5dc7c38f53b3173ff43ca29b63132ec44e672cde
--- /dev/null
+++ b/drivers/iio/accel/bma220_i2c.c
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Bosch triaxial acceleration sensor
+ *
+ * Copyright (c) 2025 Petre Rodan <petre.rodan@subdimension.ro>
+ *
+ * Datasheet: https://media.digikey.com/pdf/Data%20Sheets/Bosch/BMA220.pdf
+ * I2C address is either 0x0b or 0x0a depending on CSB (pin 10)
+ */
+
+#include <linux/errno.h>
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/types.h>
+
+#include "bma220.h"
+
+static int bma220_i2c_probe(struct i2c_client *client)
+{
+ struct regmap *regmap;
+
+ regmap = devm_regmap_init_i2c(client, &bma220_i2c_regmap_config);
+ if (IS_ERR(regmap))
+ return dev_err_probe(&client->dev, PTR_ERR(regmap),
+ "failed to create regmap\n");
+
+ return bma220_common_probe(&client->dev, regmap, client->irq);
+}
+
+static const struct of_device_id bma220_i2c_match[] = {
+ { .compatible = "bosch,bma220" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, bma220_i2c_match);
+
+static const struct i2c_device_id bma220_i2c_id[] = {
+ { "bma220" },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, bma220_i2c_id);
+
+static struct i2c_driver bma220_i2c_driver = {
+ .driver = {
+ .name = "bma220_i2c",
+ .pm = pm_sleep_ptr(&bma220_pm_ops),
+ .of_match_table = bma220_i2c_match,
+ },
+ .probe = bma220_i2c_probe,
+ .id_table = bma220_i2c_id,
+};
+module_i2c_driver(bma220_i2c_driver);
+
+MODULE_AUTHOR("Petre Rodan <petre.rodan@subdimension.ro>");
+MODULE_DESCRIPTION("Bosch triaxial acceleration sensor i2c driver");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("IIO_BOSCH_BMA220");
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 14/19] iio: accel: bma220: add i2c module
2025-10-05 13:12 ` [PATCH v4 14/19] iio: accel: bma220: add i2c module Petre Rodan
@ 2025-10-12 15:17 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 15:17 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:23 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> 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.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
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
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 15/19] iio: accel: bma220: add i2c watchdog feature
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (13 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 14/19] iio: accel: bma220: add i2c module Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 15:20 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 16/19] iio: accel: bma220: add interrupt trigger Petre Rodan
` (3 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
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.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
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(+)
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index a3faf1f5ec6d79f2c6105697b404d6eb1f4501db..a957751be40c63c25963283be813db97f73bf004 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -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;
}
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 15/19] iio: accel: bma220: add i2c watchdog feature
2025-10-05 13:12 ` [PATCH v4 15/19] iio: accel: bma220: add i2c watchdog feature Petre Rodan
@ 2025-10-12 15:20 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 15:20 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:24 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> 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.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Applied.
Thanks.
J
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 16/19] iio: accel: bma220: add interrupt trigger
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (14 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 15/19] iio: accel: bma220: add i2c watchdog feature Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 15:21 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 17/19] iio: accel: bma220: add LPF cut-off frequency mapping Petre Rodan
` (2 subsequent siblings)
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
Add interrupt trigger.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
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(+)
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index a957751be40c63c25963283be813db97f73bf004..8f0cbd0aacb92a21afc57aaa350547d0c767d4b6 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -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;
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 16/19] iio: accel: bma220: add interrupt trigger
2025-10-05 13:12 ` [PATCH v4 16/19] iio: accel: bma220: add interrupt trigger Petre Rodan
@ 2025-10-12 15:21 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 15:21 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:25 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Add interrupt trigger.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Applied.
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 17/19] iio: accel: bma220: add LPF cut-off frequency mapping
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (15 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 16/19] iio: accel: bma220: add interrupt trigger Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 15:23 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 18/19] iio: accel: bma220: add debugfs reg access Petre Rodan
2025-10-05 13:12 ` [PATCH v4 19/19] iio: accel: bma220: add maintainer Petre Rodan
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
Add mapping for the low pass filter cut-off frequency.
Make valid values visible for both the cut-off frequency and the scale.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
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(-)
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index 8f0cbd0aacb92a21afc57aaa350547d0c767d4b6..7109759e28397d2660f17707124a8803a254cb14 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -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;
}
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 17/19] iio: accel: bma220: add LPF cut-off frequency mapping
2025-10-05 13:12 ` [PATCH v4 17/19] iio: accel: bma220: add LPF cut-off frequency mapping Petre Rodan
@ 2025-10-12 15:23 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 15:23 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:26 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Add mapping for the low pass filter cut-off frequency.
> Make valid values visible for both the cut-off frequency and the scale.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Applied.
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 18/19] iio: accel: bma220: add debugfs reg access
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (16 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 17/19] iio: accel: bma220: add LPF cut-off frequency mapping Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 15:24 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 19/19] iio: accel: bma220: add maintainer Petre Rodan
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
Allow read/write access to sensor registers for use in unit-tests.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v1->v4 no change
---
drivers/iio/accel/bma220_core.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index 7109759e28397d2660f17707124a8803a254cb14..0d6c301b1c47a04cfca5bae157f8ce6144f0b854 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -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)
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 18/19] iio: accel: bma220: add debugfs reg access
2025-10-05 13:12 ` [PATCH v4 18/19] iio: accel: bma220: add debugfs reg access Petre Rodan
@ 2025-10-12 15:24 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 15:24 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:27 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Allow read/write access to sensor registers for use in unit-tests.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Applied.
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v4 19/19] iio: accel: bma220: add maintainer
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
` (17 preceding siblings ...)
2025-10-05 13:12 ` [PATCH v4 18/19] iio: accel: bma220: add debugfs reg access Petre Rodan
@ 2025-10-05 13:12 ` Petre Rodan
2025-10-12 15:24 ` Jonathan Cameron
18 siblings, 1 reply; 42+ messages in thread
From: Petre Rodan @ 2025-10-05 13:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Cameron, linux-iio, devicetree, linux-kernel
Add maintainer for this driver.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v1->v4 no change
---
MAINTAINERS | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index f090c2f6e63a0d255a025885cc4573f5802ef159..aaeb4ae6fd2282264da7e61b6fc32c00fc90a5ae 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -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 <petre.rodan@subdimension.ro>
+L: linux-iio@vger.kernel.org
+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 <dan@dlrobertson.com>
L: linux-iio@vger.kernel.org
--
2.49.1
^ permalink raw reply related [flat|nested] 42+ messages in thread* Re: [PATCH v4 19/19] iio: accel: bma220: add maintainer
2025-10-05 13:12 ` [PATCH v4 19/19] iio: accel: bma220: add maintainer Petre Rodan
@ 2025-10-12 15:24 ` Jonathan Cameron
0 siblings, 0 replies; 42+ messages in thread
From: Jonathan Cameron @ 2025-10-12 15:24 UTC (permalink / raw)
To: Petre Rodan
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, linux-iio,
devicetree, linux-kernel
On Sun, 05 Oct 2025 16:12:28 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Add maintainer for this driver.
>
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Applied. Thanks for stepping up to maintain this going forwards
Jonathan
> ---
> v1->v4 no change
> ---
> MAINTAINERS | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index f090c2f6e63a0d255a025885cc4573f5802ef159..aaeb4ae6fd2282264da7e61b6fc32c00fc90a5ae 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -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 <petre.rodan@subdimension.ro>
> +L: linux-iio@vger.kernel.org
> +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 <dan@dlrobertson.com>
> L: linux-iio@vger.kernel.org
>
^ permalink raw reply [flat|nested] 42+ messages in thread