Skip to contentSkip to conversation

iio: accel: bma400: add support for bma400 spi

PATCH Superseded Dan Robertson 2 participants 4 messages May 22, 2020 – May 25, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Dan Robertson

author maintainer
#0 lore raw

cover iio: accel: bma400: add support for bma400 spi

The Bosch Sensortec BMA400 3-axes ultra-low power supports a 4 wire SPI ditital interface. This patch adds support for the device when configured for SPI instead of I2C.

I was originally hoping to avoid using a regmap_bus definition, but the register reads from the device are padded by a byte while register writes are not padded. As a result, a regmap_config like the following does not work.

const struct regmap_config bma400_regmap_spi_config = {
    reg_bits = 8,
    pad_bits = 8,
    val_bits = 8,
    read_flag_mask = BIT(7),
    max_register = BMA400_CMD_REG,
};

I used a regmap_bus structure with read and write implementations to work around this, but would appreciate feedback on this approach and my implementation.

Cheers,

- Dan

Dan Robertson (1):
iio: accel: bma400: add support for bma400 spi

 drivers/iio/accel/Kconfig      |   8 ++-
 drivers/iio/accel/Makefile     |   1 +
 drivers/iio/accel/bma400_spi.c | 126 +++++++++++++++++++++++++++++++++
 3 files changed, 134 insertions(+), 1 deletion(-)
 create mode 100644 drivers/iio/accel/bma400_spi.c
author maintainer
#1 lore raw

PATCH 1/1 iio: accel: bma400: add support for bma400 spi

Add basic support for the Bosch Sensortec BMA400 3-axes ultra-low power accelerometer when configured to use SPI.

---
 drivers/iio/accel/Kconfig      |   8 ++-
 drivers/iio/accel/Makefile     |   1 +
 drivers/iio/accel/bma400_spi.c | 126 +++++++++++++++++++++++++++++++++
 3 files changed, 134 insertions(+), 1 deletion(-)
 create mode 100644 drivers/iio/accel/bma400_spi.c
drivers/iio/accel/Kconfig +7 -1
index 24ebe9e76915..cb4ef367e5fa 100644
@@ -116,18 +116,24 @@ config BMA400
 	tristate "Bosch BMA400 3-Axis Accelerometer Driver"
 	select REGMAP
 	select BMA400_I2C if I2C
+	select BMA400_SPI 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 if I2C is enabled.
+	  bma400_i2c if I2C is enabled and bma400_spi if SPI is
+	  enabled.
 
 config BMA400_I2C
 	tristate
 	depends on BMA400
 
+config BMA400_SPI
+	tristate
+	depends on BMA400
+
 config BMC150_ACCEL
 	tristate "Bosch BMC150 Accelerometer Driver"
 	select IIO_BUFFER
drivers/iio/accel/Makefile +1 -0
index 3a051cf37f40..4f6c1ebe13b0 100644
@@ -16,6 +16,7 @@ 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_BMA400_SPI) += bma400_spi.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_spi.c new file +126 -0

126 lines not on this page · raw message

#2 lore raw
Quoted 3 lines · Dan Robertson

Add basic support for the Bosch Sensortec BMA400 3-axes ultra-low power accelerometer when configured to use SPI.

...

Quoted 5 lines

tristate "Bosch BMA400 3-Axis Accelerometer Driver" select REGMAP
select BMA400_I2C if I2C

+ select BMA400_SPI if I2C

This is not right.

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+#include <linux/module.h>
+#include <linux/spi/spi.h>

What's the point of dups (see below)?

drivers/iio/accel/bma400_spi.c line 15

Quoted 4 lines
drivers/iio/accel/bma400_spi.c new file +4 -0
+#include <linux/spi/spi.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/regmap.h>

Keep them ordered?

...

Quoted 1 line

+#define BMA400_SPI_READ_BUFFER_SIZE (BMA400_MAX_SPI_READ + 1)

Do wee need separate macro? It seems longer than explicit use. Do we need the original macro either?

...

drivers/iio/accel/bma400_spi.c line 32

Quoted 4 lines
drivers/iio/accel/bma400_spi.c new file +4 -0
+       /*
+        * TODO(dlrobertson): What is a reasonable length to cap
+        * this at.
+        */

Either drop this or fulfill. There is no way to leave such in the non-staging code.

...

Quoted 1 line

+ .read_flag_mask = BIT(7),

#include <linux/bits.h>

...

drivers/iio/accel/bma400_spi.c line 121

Quoted 11 lines
drivers/iio/accel/bma400_spi.c new file +10 -0
+static struct spi_driver bma400_spi_driver = {
+       .driver = {
+               .name = "bma400",
+               .of_match_table = bma400_of_spi_match,
+       },
+       .probe    = bma400_spi_probe,
+       .remove   = bma400_spi_remove,
+       .id_table = bma400_spi_ids,
+};
 
+

This blank line is not needed.

Quoted 1 line

+module_spi_driver(bma400_spi_driver);

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#3 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Dan Robertson

Add basic support for the Bosch Sensortec BMA400 3-axes ultra-low power accelerometer when configured to use SPI.

...

Quoted 7 lines
Quoted 5 lines

tristate "Bosch BMA400 3-Axis Accelerometer Driver" select REGMAP
select BMA400_I2C if I2C

+ select BMA400_SPI if I2C

This is not right.

Will fix in the second version.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+#include <linux/module.h>
+#include <linux/spi/spi.h>

What's the point of dups (see below)?

An error on my part.

Quoted 4 lines
Quoted 1 line

+#define BMA400_SPI_READ_BUFFER_SIZE (BMA400_MAX_SPI_READ + 1)

Do wee need separate macro? It seems longer than explicit use. Do we need the original macro either?

I was just trying to avoid magic values. I have no problem with removing this though.

Quoted 7 lines

drivers/iio/accel/bma400_spi.c line 32

Quoted 4 lines
drivers/iio/accel/bma400_spi.c new file +4 -0
+       /*
+        * TODO(dlrobertson): What is a reasonable length to cap
+        * this at.
+        */

Either drop this or fulfill. There is no way to leave such in the non-staging code.

I'll drop this in the next patchset version if we stick with regmap_bus implementation. We never read more than two bytes in bma400_core, so this size should be fine.

Quoted 3 lines
Quoted 1 line

+ .read_flag_mask = BIT(7),

#include <linux/bits.h>

Good catch.

Thanks for the review. I will make the changes for the next patchset version.

Cheers,

- Dan