Skip to contentSkip to conversation

iio: accel: bmi088: add i2c support for bmi088 accel driver

PATCH Superseded Jun Yan 3 participants 4 messages Dec 18, 2023 – Dec 20, 2023 IIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jun Yan

author
#0 lore raw

PATCH 1/1 iio: accel: bmi088: add i2c support for bmi088 accel driver

The BMI088, BMI085 and BMI090L accelerometer also support I2C protocol, so let's add the missing I2C support.

The I2C interface of the {BMI085,BMI088,BMI090L} is compatible with the I2C Specification UM10204 Rev. 03 (19 June 2007), available at http://www.nxp.com. The {BMI085,BMI088,BMI090L} supports I2C standard mode and fast mode, only 7-bit address mode is supported.[1][2][3]

[1]: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmi085-ds001.pdf
[2]: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmi088-ds001.pdf
[3]: https://mm.digikey.com/Volume0/opasdata/d220001/medias/docus/4807/BST-BMI090L-DS000-00.pdf

---
 drivers/iio/accel/Kconfig            |  8 +++-
 drivers/iio/accel/Makefile           |  1 +
 drivers/iio/accel/bmi088-accel-i2c.c | 69 ++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+), 2 deletions(-)
 create mode 100644 drivers/iio/accel/bmi088-accel-i2c.c
drivers/iio/accel/Kconfig +6 -2
index 91adcac875a4..dc92cf599acb 100644
@@ -254,11 +254,11 @@ config BMC150_ACCEL_SPI
 
 config BMI088_ACCEL
 	tristate "Bosch BMI088 Accelerometer Driver"
-	depends on SPI
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
 	select REGMAP
-	select BMI088_ACCEL_SPI
+	select BMI088_ACCEL_SPI if SPI
+	select BMI088_ACCEL_I2C if I2C
 	help
 	  Say yes here to build support for the following Bosch accelerometers:
 	  BMI088, BMI085, BMI090L. Note that all of these are combo module that
@@ -267,6 +267,10 @@ config BMI088_ACCEL
 	  This driver only implements the accelerometer part, which has its own
 	  address and register map. BMG160 provides the gyroscope driver.
 
+config BMI088_ACCEL_I2C
+	tristate
+	select REGMAP_I2C
+
 config BMI088_ACCEL_SPI
 	tristate
 	select REGMAP_SPI
drivers/iio/accel/Makefile +1 -0
index 311ead9c3ef1..db90532ba24a 100644
@@ -30,6 +30,7 @@ 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
 obj-$(CONFIG_BMI088_ACCEL) += bmi088-accel-core.o
+obj-$(CONFIG_BMI088_ACCEL_I2C) += bmi088-accel-i2c.o
 obj-$(CONFIG_BMI088_ACCEL_SPI) += bmi088-accel-spi.o
 obj-$(CONFIG_DA280)	+= da280.o
 obj-$(CONFIG_DA311)	+= da311.o
drivers/iio/accel/bmi088-accel-i2c.c new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw
kernel test robot noticed the following build errors:

Hi Jun,

kernel test robot noticed the following build errors:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on linus/master v6.7-rc6 next-20231218] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jun-Yan/iio-accel-bmi088-add-i2c-support-for-bmi088-accel-driver/20231218-235104
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20231218154045.219317-1-jerrysteve1101%40gmail.com
patch subject: [PATCH] iio: accel: bmi088: add i2c support for bmi088 accel driver
config: powerpc64-randconfig-r081-20231219 (https://download.01.org/0day-ci/archive/20231219/[email protected]/config)
compiler: powerpc64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231219/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/iio/accel/bmi088-accel-i2c.c:14:10: fatal error: linux/i2c/i2c.h: No such file or directory
      14 | #include <linux/i2c/i2c.h>
         |          ^~~~~~~~~~~~~~~~~

compilation terminated.

vim +14 drivers/iio/accel/bmi088-accel-i2c.c

  > 14	#include <linux/i2c/i2c.h>
    15	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#2 lore raw
In reply to Jun Yan
kernel test robot noticed the following build errors:

Hi Jun,

kernel test robot noticed the following build errors:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on linus/master v6.7-rc6 next-20231218] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jun-Yan/iio-accel-bmi088-add-i2c-support-for-bmi088-accel-driver/20231218-235104
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20231218154045.219317-1-jerrysteve1101%40gmail.com
patch subject: [PATCH] iio: accel: bmi088: add i2c support for bmi088 accel driver
config: x86_64-randconfig-161-20231219 (https://download.01.org/0day-ci/archive/20231219/[email protected]/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231219/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/iio/accel/bmi088-accel-i2c.c:14:10: fatal error: 'linux/i2c/i2c.h' file not found
   #include <linux/i2c/i2c.h>
            ^~~~~~~~~~~~~~~~~

1 error generated.

vim +14 drivers/iio/accel/bmi088-accel-i2c.c

  > 14	#include <linux/i2c/i2c.h>
    15	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#3 lore raw
In reply to Jun Yan
Quoted 7 lines · On Mon, 18 Dec 2023 23:40:45 +0800 Jun Yan <[email protected]> wrote:

The BMI088, BMI085 and BMI090L accelerometer also support I2C protocol, so let's add the missing I2C support.

The I2C interface of the {BMI085,BMI088,BMI090L} is compatible with the I2C Specification UM10204 Rev. 03 (19 June 2007), available at http://www.nxp.com. The {BMI085,BMI088,BMI090L} supports I2C standard mode and fast mode, only 7-bit address mode is supported.[1][2][3]

Quoted 5 lines

[1]: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmi085-ds001.pdf
[2]: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmi088-ds001.pdf
[3]: https://mm.digikey.com/Volume0/opasdata/d220001/medias/docus/4807/BST-BMI090L-DS000-00.pdf

Hi Jun Yan

The header bug that 0-day found is curious given I'm not sure how you built this with that wrong path... Anyhow, a local quirk probably!

One comment inline, but it's asking for a significant refactor of the bmi088 core code so I don't mind if you say you'd rather leave that for another time.

Jonathan

Quoted 22 lines
drivers/iio/accel/Makefile +1 -0
index 311ead9c3ef1..db90532ba24a 100644
@@ -30,6 +30,7 @@ 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
 obj-$(CONFIG_BMI088_ACCEL) += bmi088-accel-core.o
+obj-$(CONFIG_BMI088_ACCEL_I2C) += bmi088-accel-i2c.o
 obj-$(CONFIG_BMI088_ACCEL_SPI) += bmi088-accel-spi.o
 obj-$(CONFIG_DA280)	+= da280.o
 obj-$(CONFIG_DA311)	+= da311.o
drivers/iio/accel/bmi088-accel-i2c.c new file +4 -0
new file mode 100644
index 000000000000..1dcca0e88c1a
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * 3-axis accelerometer driver supporting following Bosch-Sensortec chips:
+ *  - BMI088

drivers/iio/accel/bmi088-accel-i2c.c line 14

Quoted 10 lines
drivers/iio/accel/bmi088-accel-i2c.c new file +10 -0
+ *  - BMI085
+ *  - BMI090L
+ *
+ * Copyright 2023 Jun Yan <[email protected]>
+ */
+
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/i2c/i2c.h>

Path wrong... linux/i2c.h

drivers/iio/accel/bmi088-accel-i2c.c line 21

Quoted 7 lines
drivers/iio/accel/bmi088-accel-i2c.c new file +7 -0
+
+#include "bmi088-accel.h"
+
+static int bmi088_accel_probe(struct i2c_device *i2c)
+{
+	struct regmap *regmap;
+	const struct i2c_device_id *id = i2c_get_device_id(i2c);

Hmm. So ideally you would do the following... But it's a major rework to bring the bmi088 up to date with the new helpers so I'll take this without if you'd prefer the simple solution and we can look at the refactor as a follow up patch (particularly if you are happy to test the changes!)

Please add data to bmi088_of_match_data() and then use the more flexible method of i2c_get_match_data()

Using the device ID runs into corner cases with fallback compatibles where a match might not be found.

Note that to do this you will need to make the bmi088_accel_core_probe() take a pointer to the chip info + make that data available to this

Quoted 48 lines
drivers/iio/accel/bmi088-accel-i2c.c new file +48 -0
+
+	regmap = devm_regmap_init_i2c(&i2c->dev, &bmi088_regmap_conf);
+	if (IS_ERR(regmap)) {
+		dev_err(&i2c->dev, "Failed to initialize i2c regmap\n");
+		return PTR_ERR(regmap);
+	}
+
+	return bmi088_accel_core_probe(&i2c->dev, regmap, i2c->irq,
+					id->driver_data);
+}
+
+static void bmi088_accel_remove(struct i2c_device *i2c)
+{
+	bmi088_accel_core_remove(&i2c->dev);
+}
+
+static const struct of_device_id bmi088_of_match[] = {
+	{ .compatible = "bosch,bmi085-accel" },
+	{ .compatible = "bosch,bmi088-accel" },
+	{ .compatible = "bosch,bmi090l-accel" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, bmi088_of_match);
+
+static const struct i2c_device_id bmi088_accel_id[] = {
+	{"bmi085-accel",  BOSCH_BMI085},
+	{"bmi088-accel",  BOSCH_BMI088},
+	{"bmi090l-accel", BOSCH_BMI090L},
+	{}
+};
+MODULE_DEVICE_TABLE(i2c, bmi088_accel_id);
+
+static struct i2c_driver bmi088_accel_driver = {
+	.driver = {
+		.name	= "bmi088_accel_i2c",
+		.pm	= pm_ptr(&bmi088_accel_pm_ops),
+		.of_match_table = bmi088_of_match,
+	},
+	.probe		= bmi088_accel_probe,
+	.remove		= bmi088_accel_remove,
+	.id_table	= bmi088_accel_id,
+};
+module_i2c_driver(bmi088_accel_driver);
+
+MODULE_AUTHOR("Jun Yan <[email protected]>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("BMI088 accelerometer driver (I2C)");
+MODULE_IMPORT_NS(IIO_BMI088);