Skip to contentSkip to conversation

iio: add driver for Bosch BMA400 accelerometer

PATCH Superseded Dan Robertson 2 participants 5 messages Dec 9, 2019

Subsystems (3)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Dan Robertson

author maintainer
#0 lore raw

v5 cover iio: add driver for Bosch BMA400 accelerometer

This patchset adds a IIO driver for the Bosch BMA400 3-axes ultra low-power accelerometer. The initial implementation of the driver adds read support for the acceleration and temperature data registers. The driver also has support for reading and writing to the output data rate, oversampling ratio, and scale configuration registers.

The major update in this patchset version is the move from using tables to convert user input to/from the raw register value to using a function.

Tests run:
- Various tests with libiio and i2c-dev
- dtbs_check and dt_binding_check

Thanks again for the reviews of patches v4! If I missed anything please let me know.

Cheers,

- Dan

Changes in v5:

* Move to using a function instead of lookup tables for scale and frequency conversions.
* Rename DT bindings to bosch,bma400.yaml
* Fixed other errors and improvements found by reviewers

Changes in v4:

* Fix error in DT bindings
* Fix typo when setting the OSR
* Simplified the cached sample frequency
* Fix the MODULE_LICENSE

Changes in v3:

* Use yaml format for DT bindings
* Remove strict dependency on OF
* Tidy Kconfig dependencies
* Stylistic changes
* Do not soft-reset device on remove

Changes in v2:

* Implemented iio_info -> read_avail
* Stylistic changes
* Implemented devicetree bindings

Dan Robertson (2):
dt-bindings: iio: accel: bma400: add bindings
iio: (bma400) add driver for the BMA400

 .../bindings/iio/accel/bosch,bma400.yaml      |  39 +
 drivers/iio/accel/Kconfig                     |  16 +
 drivers/iio/accel/Makefile                    |   2 +
 drivers/iio/accel/bma400.h                    |  95 ++
 drivers/iio/accel/bma400_core.c               | 823 ++++++++++++++++++
 drivers/iio/accel/bma400_i2c.c                |  62 ++
 6 files changed, 1037 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/accel/bosch,bma400.yaml
 create mode 100644 drivers/iio/accel/bma400.h
 create mode 100644 drivers/iio/accel/bma400_core.c
 create mode 100644 drivers/iio/accel/bma400_i2c.c
author maintainer
#1 lore raw

PATCH v5 1/2 dt-bindings: iio: accel: bma400: add bindings

Add devicetree binding for the Bosch BMA400 3-axes ultra-low power accelerometer sensor.

---
 .../bindings/iio/accel/bosch,bma400.yaml      | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/accel/bosch,bma400.yaml
Documentation/devicetree/bindings/iio/accel/bosch,bma400.yaml new file +39 -0
new file mode 100644
index 000000000000..03b7ad345523
@@ -0,0 +1,39 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/accel/bosch,bma400.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Bosch BMA400 triaxial acceleration sensor
+
+maintainers:
+  - Dan Robertson <[email protected]>
+
+description: |
+  Acceleration and temerature iio sensors with an i2c interface
+
+  Specifications about the sensor can be found at:
+    https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMA400-DS000.pdf
+
+properties:
+  compatible:
+    enum:
+      - bosch,bma400
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      accelerometer@14 {
+        compatible = "bosch,bma400";
+        reg = <0x14>;
+      };
+    };
author maintainer
#2 lore raw

PATCH v5 2/2 iio: (bma400) add driver for the BMA400

In reply to Dan Robertson

Add a IIO driver for the Bosch BMA400 3-axes ultra-low power accelerometer. The driver supports reading from the acceleration and temperature registers. The driver also supports reading and configuring the output data rate, oversampling ratio, and scale.

---
 drivers/iio/accel/Kconfig       |  16 +
 drivers/iio/accel/Makefile      |   2 +
 drivers/iio/accel/bma400.h      |  95 ++++
 drivers/iio/accel/bma400_core.c | 823 ++++++++++++++++++++++++++++++++
 drivers/iio/accel/bma400_i2c.c  |  62 +++
 5 files changed, 998 insertions(+)
 create mode 100644 drivers/iio/accel/bma400.h
 create mode 100644 drivers/iio/accel/bma400_core.c
 create mode 100644 drivers/iio/accel/bma400_i2c.c
drivers/iio/accel/Kconfig +16 -0
index d4ef35aeb579..dc9bc646d403 100644
@@ -112,6 +112,22 @@ config BMA220
 	  To compile this driver as a module, choose M here: the
 	  module will be called bma220_spi.
 
+config BMA400
+	tristate "Bosch BMA400 3-Axis Accelerometer Driver"
+	select REGMAP
+	select BMA400_I2C if (I2C)
+	help
+	  Say Y here if you want to build a driver for the Bosch BMA400
+	  triaxial acceleration sensor.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called bma400_core and you will also get
+	  bma400_i2c for I2C.
+
+config BMA400_I2C
+	tristate
+	depends on BMA400
+
 config BMC150_ACCEL
 	tristate "Bosch BMC150 Accelerometer Driver"
 	select IIO_BUFFER
drivers/iio/accel/Makefile +2 -0
index 56bd0215e0d4..3a051cf37f40 100644
@@ -14,6 +14,8 @@ obj-$(CONFIG_ADXL372_I2C) += adxl372_i2c.o
 obj-$(CONFIG_ADXL372_SPI) += adxl372_spi.o
 obj-$(CONFIG_BMA180) += bma180.o
 obj-$(CONFIG_BMA220) += bma220_spi.o
+obj-$(CONFIG_BMA400) += bma400_core.o
+obj-$(CONFIG_BMA400_I2C) += bma400_i2c.o
 obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o
 obj-$(CONFIG_BMC150_ACCEL_I2C) += bmc150-accel-i2c.o
 obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o
drivers/iio/accel/bma400.h new file +95 -0

95 lines not on this page · raw message

drivers/iio/accel/bma400_core.c new file +823 -0

823 lines not on this page · raw message

drivers/iio/accel/bma400_i2c.c new file +62 -0

62 lines not on this page · raw message

#3 lore raw

Re: [PATCH v5 2/2] iio: (bma400) add driver for the BMA400

Hi,

drivers/iio/accel/Kconfig config BMA220 · line 118

Quoted 12 lines · Dan Robertson
drivers/iio/accel/Kconfig +4 -0
index d4ef35aeb579..dc9bc646d403 100644
@@ -112,6 +112,22 @@ config BMA220
 	  To compile this driver as a module, choose M here: the
 	  module will be called bma220_spi.
 
+config BMA400
+	tristate "Bosch BMA400 3-Axis Accelerometer Driver"
+	select REGMAP
+	select BMA400_I2C if (I2C)

What's with the parentheses? I see that there are roughly 2700 "select ... if X" without parens and around 95 like "select ... if (" [using rough grep expressions]. The parens are unnecessary. They are often used on complex expressions, but certainly not on simple ones (except in iio).

drivers/iio/accel/Kconfig config BMA220 · line 125

Quoted 7 lines
drivers/iio/accel/Kconfig +7 -0
+	help
+	  Say Y here if you want to build a driver for the Bosch BMA400
+	  triaxial acceleration sensor.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called bma400_core and you will also get
+	  bma400_i2c for I2C.

iff I2C is set/enabled, so could be confusing.

Quoted 8 lines
drivers/iio/accel/Kconfig +5 -0
+
+config BMA400_I2C
+	tristate
+	depends on BMA400
+
 config BMC150_ACCEL
 	tristate "Bosch BMC150 Accelerometer Driver"
 	select IIO_BUFFER
Signature · 1 line
~Randy
author maintainer
#4 lore raw

Re: [PATCH v5 2/2] iio: (bma400) add driver for the BMA400

Quoted 9 lines · Randy Dunlap
Quoted 8 lines · Dan Robertson
drivers/iio/accel/Kconfig +0 -0
index d4ef35aeb579..dc9bc646d403 100644
@@ -112,6 +112,22 @@ config BMA220
 	  To compile this driver as a module, choose M here: the
 	  module will be called bma220_spi.
 
Quoted 10 lines

drivers/iio/accel/Kconfig config BMA220 · line 118

Quoted 4 lines
drivers/iio/accel/Kconfig +4 -0
+config BMA400
+	tristate "Bosch BMA400 3-Axis Accelerometer Driver"
+	select REGMAP
+	select BMA400_I2C if (I2C)

What's with the parentheses? I see that there are roughly 2700 "select ... if X" without parens and around 95 like "select ... if (" [using rough grep expressions]. The parens are unnecessary. They are often used on complex expressions, but certainly not on simple ones (except in iio).

Good point. I'll remove it. I'll need the parentheses if/when SPI support is added, but I'll add it when it is needed.

Quoted 9 lines

drivers/iio/accel/Kconfig config BMA220 · line 125

Quoted 7 lines
drivers/iio/accel/Kconfig +7 -0
+	help
+	  Say Y here if you want to build a driver for the Bosch BMA400
+	  triaxial acceleration sensor.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called bma400_core and you will also get
+	  bma400_i2c for I2C.

iff I2C is set/enabled, so could be confusing.

Good catch.

Cheers,

- Dan