Skip to contentSkip to conversation

Add I2C driver for Bosch BMI270 IMU

PATCH Superseded Alex Lanzano 4 participants 10 messages Sep 9, 2024 – Sep 14, 2024

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Alex Lanzano

author maintainer
#0 lore raw

v3 cover Add I2C driver for Bosch BMI270 IMU

Add basic I2C support for the Bosch BMI270 IMU.

References:
https://www.bosch-sensortec.com/products/motion-sensors/imus/bmi270/

---
Changes in v3:
- Remove code pertaining to buffer / triggered buffer
- Move register definitions from struct to defines
- Add bit mask defines for registers and replace hardcoded values
- Create macros for accel and gryo channels
- Code style cleanup

Changes in v2:
- Remove spi example in binding documentation
- Add more properties to i2c example in binding documentation
---

Alex Lanzano (2):
dt-bindings: iio: imu: add bmi270 bindings
iio: imu: Add i2c driver for bmi270 imu

 .../bindings/iio/imu/bosch,bmi270.yaml        |  77 ++++++
 MAINTAINERS                                   |   7 +
 drivers/iio/imu/Kconfig                       |   1 +
 drivers/iio/imu/Makefile                      |   1 +
 drivers/iio/imu/bmi270/Kconfig                |  21 ++
 drivers/iio/imu/bmi270/Makefile               |   6 +
 drivers/iio/imu/bmi270/bmi270.h               |  62 +++++
 drivers/iio/imu/bmi270/bmi270_core.c          | 251 ++++++++++++++++++
 drivers/iio/imu/bmi270/bmi270_i2c.c           |  48 ++++
 9 files changed, 474 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/bosch,bmi270.yaml
 create mode 100644 drivers/iio/imu/bmi270/Kconfig
 create mode 100644 drivers/iio/imu/bmi270/Makefile
 create mode 100644 drivers/iio/imu/bmi270/bmi270.h
 create mode 100644 drivers/iio/imu/bmi270/bmi270_core.c
 create mode 100644 drivers/iio/imu/bmi270/bmi270_i2c.c
Signature · 1 line
2.46.0
author maintainer
#1 lore raw

PATCH v3 1/2 dt-bindings: iio: imu: add bmi270 bindings

Add device tree bindings for the bmi270 IMU

---
 .../bindings/iio/imu/bosch,bmi270.yaml        | 77 +++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/bosch,bmi270.yaml
Documentation/devicetree/bindings/iio/imu/bosch,bmi270.yaml new file +77 -0
new file mode 100644
index 000000000000..792d1483af3c
@@ -0,0 +1,77 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/imu/bosch,bmi270.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Bosch BMI270 6-Axis IMU
+
+maintainers:
+  - Alex Lanzano <[email protected]>
+
+description: |
+  BMI270 is a 6-axis inertial measurement unit that can measure acceleration and
+  angular velocity. The sensor also supports configurable interrupt events such
+  as motion, step counter, and wrist motion gestures. The sensor can communicate
+  I2C or SPI.
+  https://www.bosch-sensortec.com/products/motion-sensors/imus/bmi270/
+
+properties:
+  compatible:
+    const: bosch,bmi270
+
+  reg:
+    maxItems: 1
+
+  vdd-supply: true
+  vddio-supply: true
+
+  interrupts:
+    minItems: 1
+    maxItems: 2
+
+  interrupt-names:
+    minItems: 1
+    maxItems: 2
+    items:
+      enum:
+        - INT1
+        - INT2
+
+  drive-open-drain:
+    description:
+      set if the specified interrupt pins should be configured as
+      open drain. If not set, defaults to push-pull.
+
+  mount-matrix:
+    description:
+      an optional 3x3 mounting rotation matrix.
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+  - vddio-supply
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        imu@68 {
+            compatible = "bosch,bmi270";
+            reg = <0x68>;
+            vdd-supply = <&vdd>;
+            vddio-supply = <&vddio>;
+            interrupt-parent = <&gpio1>;
+            interrupts = <16 IRQ_TYPE_EDGE_RISING>;
+            interrupt-names = "INT1";
+        };
+    };
Signature · 1 line
2.46.0
author maintainer
#2 lore raw

PATCH v3 2/2 iio: imu: Add i2c driver for bmi270 imu

In reply to Alex Lanzano

Add initial i2c support for the Bosch BMI270 6-axis IMU. Provides raw read access to acceleration and angle velocity measurements via iio channels. Device configuration requires firmware provided by Bosch and is requested and load from userspace.

---
 MAINTAINERS                          |   7 +
 drivers/iio/imu/Kconfig              |   1 +
 drivers/iio/imu/Makefile             |   1 +
 drivers/iio/imu/bmi270/Kconfig       |  21 +++
 drivers/iio/imu/bmi270/Makefile      |   6 +
 drivers/iio/imu/bmi270/bmi270.h      |  62 +++++++
 drivers/iio/imu/bmi270/bmi270_core.c | 251 +++++++++++++++++++++++++++
 drivers/iio/imu/bmi270/bmi270_i2c.c  |  48 +++++
 8 files changed, 397 insertions(+)
 create mode 100644 drivers/iio/imu/bmi270/Kconfig
 create mode 100644 drivers/iio/imu/bmi270/Makefile
 create mode 100644 drivers/iio/imu/bmi270/bmi270.h
 create mode 100644 drivers/iio/imu/bmi270/bmi270_core.c
 create mode 100644 drivers/iio/imu/bmi270/bmi270_i2c.c
MAINTAINERS +7 -0
index a2184637a5d9..6612d27525b5 100644
@@ -3928,6 +3928,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/iio/accel/bosch,bma400.yaml
 F:	drivers/iio/accel/bma400*
 
+BOSCH SENSORTEC BMI270 IMU IIO DRIVER
+M:	Alex Lanzano <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/imu/bosch,bmi270.yaml
+F:	drivers/iio/imu/bmi270/
+
 BOSCH SENSORTEC BMI323 IMU IIO DRIVER
 M:	Jagath Jog J <[email protected]>
 L:	[email protected]
drivers/iio/imu/Kconfig +1 -0
index 782fb80e44c2..489dd898830b 100644
@@ -53,6 +53,7 @@ config ADIS16480
 	  ADIS16485, ADIS16488 inertial sensors.
 
 source "drivers/iio/imu/bmi160/Kconfig"
+source "drivers/iio/imu/bmi270/Kconfig"
 source "drivers/iio/imu/bmi323/Kconfig"
 source "drivers/iio/imu/bno055/Kconfig"
 
drivers/iio/imu/Makefile +1 -0
index 7e2d7d5c3b7b..79f83ea6f644 100644
@@ -15,6 +15,7 @@ adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_buffer.o
 obj-$(CONFIG_IIO_ADIS_LIB) += adis_lib.o
 
 obj-y += bmi160/
+obj-y += bmi270/
 obj-y += bmi323/
 obj-y += bno055/
 
drivers/iio/imu/bmi270/Kconfig new file +21 -0
new file mode 100644
index 000000000000..3f7b4ac30f00
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# BMI270 IMU driver
+#
+
+config BMI270
+	tristate
+	select IIO_BUFFER
+
+config BMI270_I2C
+	tristate "Bosch BMI270 I2C driver"
+	depends on I2C
+	select BMI270
+	select REGMAP_I2C
+	help
+	  Enable support for the Bosch BMI270 6-Axis IMU connected to I2C
+	  interface.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called bmi270_i2c.
+
drivers/iio/imu/bmi270/Makefile new file +6 -0
new file mode 100644
index 000000000000..ab4acaaee6d2
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for Bosch BMI270 IMU
+#
+obj-$(CONFIG_BMI270) += bmi270_core.o
+obj-$(CONFIG_BMI270_I2C) += bmi270_i2c.o
drivers/iio/imu/bmi270/bmi270.h new file +62 -0

62 lines not on this page · raw message

drivers/iio/imu/bmi270/bmi270_core.c new file +251 -0

251 lines not on this page · raw message

drivers/iio/imu/bmi270/bmi270_i2c.c new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.46.0
#3 lore raw

Re: [PATCH v3 2/2] iio: imu: Add i2c driver for bmi270 imu

kernel test robot noticed the following build errors:

Hi Alex,

kernel test robot noticed the following build errors:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on robh/for-next linus/master v6.11-rc7 next-20240909] [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/Alex-Lanzano/dt-bindings-iio-imu-add-bmi270-bindings/20240909-123509
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20240909043254.611589-3-lanzano.alex%40gmail.com
patch subject: [PATCH v3 2/2] iio: imu: Add i2c driver for bmi270 imu
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20240910/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240910/[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/imu/bmi270/bmi270_core.c: In function 'bmi270_configure_imu':

>> drivers/iio/imu/bmi270/bmi270_core.c:180:31: error: implicit declaration of function 'FIELD_PREP' [-Wimplicit-function-declaration]
     180 |                               FIELD_PREP(BMI270_ACC_CONF_ODR_MSK,
         |                               ^~~~~~~~~~

vim +/FIELD_PREP +180 drivers/iio/imu/bmi270/bmi270_core.c

165
166 static int bmi270_configure_imu(struct bmi270_data *bmi270_device)
167 {
168 int ret;
169 struct device *dev = bmi270_device->dev;
170 struct regmap *regmap = bmi270_device->regmap;
171
172 ret = regmap_set_bits(regmap, BMI270_PWR_CTRL_REG,

   173				      BMI270_PWR_CTRL_AUX_EN_MSK |
   174				      BMI270_PWR_CTRL_GYR_EN_MSK |
   175				      BMI270_PWR_CTRL_ACCEL_EN_MSK);
   176		if (ret)
   177			return dev_err_probe(dev, ret, "Failed to enable accelerometer and gyroscope");
   178	
   179		ret = regmap_set_bits(regmap, BMI270_ACC_CONF_REG,
 > 180				      FIELD_PREP(BMI270_ACC_CONF_ODR_MSK,

181 BMI270_ACC_CONF_ODR_100HZ) |
182 FIELD_PREP(BMI270_ACC_CONF_BWP_MSK,
183 BMI270_ACC_CONF_BWP_NORMAL_MODE) |
184 BMI270_PWR_CONF_ADV_PWR_SAVE_MSK);
185 if (ret)
186 return dev_err_probe(dev, ret, "Failed to configure accelerometer");
187
188 ret = regmap_set_bits(regmap, BMI270_GYR_CONF_REG,
189 FIELD_PREP(BMI270_GYR_CONF_ODR_MSK,
190 BMI270_GYR_CONF_ODR_200HZ) |
191 FIELD_PREP(BMI270_GYR_CONF_BWP_MSK,
192 BMI270_GYR_CONF_BWP_NORMAL_MODE) |
193 BMI270_PWR_CONF_ADV_PWR_SAVE_MSK);
194 if (ret)
195 return dev_err_probe(dev, ret, "Failed to configure gyroscope");
196
197 /* Enable FIFO_WKUP, Disable ADV_PWR_SAVE and FUP_EN */
198 ret = regmap_write(regmap, BMI270_PWR_CONF_REG,
199 BMI270_PWR_CONF_FIFO_WKUP_MSK);
200 if (ret)
201 return dev_err_probe(dev, ret, "Failed to set power configuration");
202
203 return 0;
204 }
205

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#4 lore raw

Re: [PATCH v3 2/2] iio: imu: Add i2c driver for bmi270 imu

Quoted 66 lines · kernel test robot

Hi Alex,

kernel test robot noticed the following build errors:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on robh/for-next linus/master v6.11-rc7 next-20240909] [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/Alex-Lanzano/dt-bindings-iio-imu-add-bmi270-bindings/20240909-123509
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20240909043254.611589-3-lanzano.alex%40gmail.com
patch subject: [PATCH v3 2/2] iio: imu: Add i2c driver for bmi270 imu
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20240910/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240910/[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/imu/bmi270/bmi270_core.c: In function 'bmi270_configure_imu':
Quoted 1 line
Quoted 1 line

drivers/iio/imu/bmi270/bmi270_core.c:180:31: error: implicit declaration of function 'FIELD_PREP' [-Wimplicit-function-declaration]

     180 |                               FIELD_PREP(BMI270_ACC_CONF_ODR_MSK,
         |                               ^~~~~~~~~~

vim +/FIELD_PREP +180 drivers/iio/imu/bmi270/bmi270_core.c

   165	
   166	static int bmi270_configure_imu(struct bmi270_data *bmi270_device)
   167	{
   168		int ret;
   169		struct device *dev = bmi270_device->dev;
   170		struct regmap *regmap = bmi270_device->regmap;
   171	
   172		ret = regmap_set_bits(regmap, BMI270_PWR_CTRL_REG,
   173				      BMI270_PWR_CTRL_AUX_EN_MSK |
   174				      BMI270_PWR_CTRL_GYR_EN_MSK |
   175				      BMI270_PWR_CTRL_ACCEL_EN_MSK);
   176		if (ret)
   177			return dev_err_probe(dev, ret, "Failed to enable accelerometer and gyroscope");
   178	
   179		ret = regmap_set_bits(regmap, BMI270_ACC_CONF_REG,
Quoted 1 line

180 FIELD_PREP(BMI270_ACC_CONF_ODR_MSK,

181 BMI270_ACC_CONF_ODR_100HZ) |
182 FIELD_PREP(BMI270_ACC_CONF_BWP_MSK,
183 BMI270_ACC_CONF_BWP_NORMAL_MODE) |

   184				      BMI270_PWR_CONF_ADV_PWR_SAVE_MSK);
   185		if (ret)
   186			return dev_err_probe(dev, ret, "Failed to configure accelerometer");
   187	
   188		ret = regmap_set_bits(regmap, BMI270_GYR_CONF_REG,
   189				      FIELD_PREP(BMI270_GYR_CONF_ODR_MSK,
   190						 BMI270_GYR_CONF_ODR_200HZ) |
   191				      FIELD_PREP(BMI270_GYR_CONF_BWP_MSK,
   192						 BMI270_GYR_CONF_BWP_NORMAL_MODE) |
   193				      BMI270_PWR_CONF_ADV_PWR_SAVE_MSK);
   194		if (ret)
   195			return dev_err_probe(dev, ret, "Failed to configure gyroscope");
   196	
   197		/* Enable FIFO_WKUP, Disable ADV_PWR_SAVE and FUP_EN */
Quoted 12 lines
   198		ret = regmap_write(regmap, BMI270_PWR_CONF_REG,
   199				   BMI270_PWR_CONF_FIFO_WKUP_MSK);
   200		if (ret)
   201			return dev_err_probe(dev, ret, "Failed to set power configuration");
   202	
   203		return 0;
   204	}
   205	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

I am having trouble reproducing this build error on both jic23-iio/togreg and linus/master v6.11.rc7 on an aarch64 box with the same compiler version. Maybe a config option is causing this?

However, I will add #include <linux/bitfield.h> to remedy this issue if some edge case is being hit.

Best regards,
Alex

maintainer
#5 lore raw

Re: [PATCH v3 2/2] iio: imu: Add i2c driver for bmi270 imu

Quoted 80 lines · On Mon, 9 Sep 2024 23:21:52 -0400 Alex Lanzano <[email protected]> wrote:
Quoted 66 lines · kernel test robot

Hi Alex,

kernel test robot noticed the following build errors:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on robh/for-next linus/master v6.11-rc7 next-20240909] [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/Alex-Lanzano/dt-bindings-iio-imu-add-bmi270-bindings/20240909-123509
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20240909043254.611589-3-lanzano.alex%40gmail.com
patch subject: [PATCH v3 2/2] iio: imu: Add i2c driver for bmi270 imu
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20240910/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240910/[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/imu/bmi270/bmi270_core.c: In function 'bmi270_configure_imu':  
Quoted 1 line
Quoted 1 line

drivers/iio/imu/bmi270/bmi270_core.c:180:31: error: implicit declaration of function 'FIELD_PREP' [-Wimplicit-function-declaration]

     180 |                               FIELD_PREP(BMI270_ACC_CONF_ODR_MSK,
         |                               ^~~~~~~~~~

vim +/FIELD_PREP +180 drivers/iio/imu/bmi270/bmi270_core.c

   165	
   166	static int bmi270_configure_imu(struct bmi270_data *bmi270_device)
   167	{
   168		int ret;
   169		struct device *dev = bmi270_device->dev;
   170		struct regmap *regmap = bmi270_device->regmap;
   171	
   172		ret = regmap_set_bits(regmap, BMI270_PWR_CTRL_REG,
   173				      BMI270_PWR_CTRL_AUX_EN_MSK |
   174				      BMI270_PWR_CTRL_GYR_EN_MSK |
   175				      BMI270_PWR_CTRL_ACCEL_EN_MSK);
   176		if (ret)
   177			return dev_err_probe(dev, ret, "Failed to enable accelerometer and gyroscope");
   178	
   179		ret = regmap_set_bits(regmap, BMI270_ACC_CONF_REG,  
Quoted 1 line

180 FIELD_PREP(BMI270_ACC_CONF_ODR_MSK,

181 BMI270_ACC_CONF_ODR_100HZ) |
182 FIELD_PREP(BMI270_ACC_CONF_BWP_MSK,
183 BMI270_ACC_CONF_BWP_NORMAL_MODE) |

   184				      BMI270_PWR_CONF_ADV_PWR_SAVE_MSK);
   185		if (ret)
   186			return dev_err_probe(dev, ret, "Failed to configure accelerometer");
   187	
   188		ret = regmap_set_bits(regmap, BMI270_GYR_CONF_REG,
   189				      FIELD_PREP(BMI270_GYR_CONF_ODR_MSK,
   190						 BMI270_GYR_CONF_ODR_200HZ) |
   191				      FIELD_PREP(BMI270_GYR_CONF_BWP_MSK,
   192						 BMI270_GYR_CONF_BWP_NORMAL_MODE) |
   193				      BMI270_PWR_CONF_ADV_PWR_SAVE_MSK);
   194		if (ret)
   195			return dev_err_probe(dev, ret, "Failed to configure gyroscope");
   196	
   197		/* Enable FIFO_WKUP, Disable ADV_PWR_SAVE and FUP_EN */
Quoted 12 lines
   198		ret = regmap_write(regmap, BMI270_PWR_CONF_REG,
   199				   BMI270_PWR_CONF_FIFO_WKUP_MSK);
   200		if (ret)
   201			return dev_err_probe(dev, ret, "Failed to set power configuration");
   202	
   203		return 0;
   204	}
   205	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki  
Quoted 6 lines

I am having trouble reproducing this build error on both jic23-iio/togreg and linus/master v6.11.rc7 on an aarch64 box with the same compiler version. Maybe a config option is causing this?

However, I will add #include <linux/bitfield.h> to remedy this issue if some edge case is being hit.

Makes sense anyways roughly speaking we should aim for "include what you use" for headers to avoid this sort of subtle build issue.
There are exceptions for one or two headers that are always included via another path, but bitfield.h isn't one of those.

Jonathan

Quoted 3 lines

Best regards,
Alex

#6 lore raw

Re: [PATCH v3 2/2] iio: imu: Add i2c driver for bmi270 imu

In reply to Alex Lanzano
kernel test robot noticed the following build errors:

Hi Alex,

kernel test robot noticed the following build errors:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on robh/for-next linus/master v6.11-rc7 next-20240909] [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/Alex-Lanzano/dt-bindings-iio-imu-add-bmi270-bindings/20240909-123509
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20240909043254.611589-3-lanzano.alex%40gmail.com
patch subject: [PATCH v3 2/2] iio: imu: Add i2c driver for bmi270 imu
config: hexagon-allmodconfig (https://download.01.org/0day-ci/archive/20240910/[email protected]/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 05f5a91d00b02f4369f46d076411c700755ae041)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240910/[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 >>):

In file included from drivers/iio/imu/bmi270/bmi270_core.c:4:
In file included from include/linux/i2c.h:19:
In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:25:
In file included from include/linux/kernel_stat.h:8:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:14:
In file included from arch/hexagon/include/asm/io.h:328:
include/asm-generic/io.h:548:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]

     548 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:561:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     561 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
         |                                                   ^
   In file included from drivers/iio/imu/bmi270/bmi270_core.c:4:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:25:
   In file included from include/linux/kernel_stat.h:8:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:14:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:574:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     574 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
         |                                                   ^
   In file included from drivers/iio/imu/bmi270/bmi270_core.c:4:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:25:
   In file included from include/linux/kernel_stat.h:8:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:14:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:585:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     585 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:595:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     595 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:605:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     605 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   In file included from drivers/iio/imu/bmi270/bmi270_core.c:4:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:21:
   In file included from include/linux/mm.h:2228:
   include/linux/vmstat.h:517:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     517 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
>> drivers/iio/imu/bmi270/bmi270_core.c:180:10: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     180 |                               FIELD_PREP(BMI270_ACC_CONF_ODR_MSK,
         |                               ^

7 warnings and 1 error generated.

vim +/FIELD_PREP +180 drivers/iio/imu/bmi270/bmi270_core.c

165
166 static int bmi270_configure_imu(struct bmi270_data *bmi270_device)
167 {
168 int ret;
169 struct device *dev = bmi270_device->dev;
170 struct regmap *regmap = bmi270_device->regmap;
171
172 ret = regmap_set_bits(regmap, BMI270_PWR_CTRL_REG,

   173				      BMI270_PWR_CTRL_AUX_EN_MSK |
   174				      BMI270_PWR_CTRL_GYR_EN_MSK |
   175				      BMI270_PWR_CTRL_ACCEL_EN_MSK);
   176		if (ret)
   177			return dev_err_probe(dev, ret, "Failed to enable accelerometer and gyroscope");
   178	
   179		ret = regmap_set_bits(regmap, BMI270_ACC_CONF_REG,
 > 180				      FIELD_PREP(BMI270_ACC_CONF_ODR_MSK,

181 BMI270_ACC_CONF_ODR_100HZ) |
182 FIELD_PREP(BMI270_ACC_CONF_BWP_MSK,
183 BMI270_ACC_CONF_BWP_NORMAL_MODE) |
184 BMI270_PWR_CONF_ADV_PWR_SAVE_MSK);
185 if (ret)
186 return dev_err_probe(dev, ret, "Failed to configure accelerometer");
187
188 ret = regmap_set_bits(regmap, BMI270_GYR_CONF_REG,
189 FIELD_PREP(BMI270_GYR_CONF_ODR_MSK,
190 BMI270_GYR_CONF_ODR_200HZ) |
191 FIELD_PREP(BMI270_GYR_CONF_BWP_MSK,
192 BMI270_GYR_CONF_BWP_NORMAL_MODE) |
193 BMI270_PWR_CONF_ADV_PWR_SAVE_MSK);
194 if (ret)
195 return dev_err_probe(dev, ret, "Failed to configure gyroscope");
196
197 /* Enable FIFO_WKUP, Disable ADV_PWR_SAVE and FUP_EN */
198 ret = regmap_write(regmap, BMI270_PWR_CONF_REG,
199 BMI270_PWR_CONF_FIFO_WKUP_MSK);
200 if (ret)
201 return dev_err_probe(dev, ret, "Failed to set power configuration");
202
203 return 0;
204 }
205

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#7 lore raw

Re: [PATCH v3 2/2] iio: imu: Add i2c driver for bmi270 imu

Quoted 145 lines · kernel test robot

Hi Alex,

kernel test robot noticed the following build errors:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on robh/for-next linus/master v6.11-rc7 next-20240909] [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/Alex-Lanzano/dt-bindings-iio-imu-add-bmi270-bindings/20240909-123509
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20240909043254.611589-3-lanzano.alex%40gmail.com
patch subject: [PATCH v3 2/2] iio: imu: Add i2c driver for bmi270 imu
config: hexagon-allmodconfig (https://download.01.org/0day-ci/archive/20240910/[email protected]/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 05f5a91d00b02f4369f46d076411c700755ae041)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240910/[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 >>):

In file included from drivers/iio/imu/bmi270/bmi270_core.c:4:
In file included from include/linux/i2c.h:19:
In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:25:
In file included from include/linux/kernel_stat.h:8:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:14:
In file included from arch/hexagon/include/asm/io.h:328:
include/asm-generic/io.h:548:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]

     548 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:561:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     561 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
         |                                                   ^
   In file included from drivers/iio/imu/bmi270/bmi270_core.c:4:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:25:
   In file included from include/linux/kernel_stat.h:8:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:14:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:574:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     574 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
         |                                                   ^
   In file included from drivers/iio/imu/bmi270/bmi270_core.c:4:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:25:
   In file included from include/linux/kernel_stat.h:8:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:14:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:585:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     585 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:595:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     595 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:605:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     605 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   In file included from drivers/iio/imu/bmi270/bmi270_core.c:4:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:21:
   In file included from include/linux/mm.h:2228:
   include/linux/vmstat.h:517:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     517 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
Quoted 1 line
Quoted 1 line

drivers/iio/imu/bmi270/bmi270_core.c:180:10: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

     180 |                               FIELD_PREP(BMI270_ACC_CONF_ODR_MSK,
         |                               ^

7 warnings and 1 error generated.

vim +/FIELD_PREP +180 drivers/iio/imu/bmi270/bmi270_core.c

   165	
   166	static int bmi270_configure_imu(struct bmi270_data *bmi270_device)
   167	{
   168		int ret;
   169		struct device *dev = bmi270_device->dev;
   170		struct regmap *regmap = bmi270_device->regmap;
   171	
   172		ret = regmap_set_bits(regmap, BMI270_PWR_CTRL_REG,
   173				      BMI270_PWR_CTRL_AUX_EN_MSK |
   174				      BMI270_PWR_CTRL_GYR_EN_MSK |
   175				      BMI270_PWR_CTRL_ACCEL_EN_MSK);
   176		if (ret)
   177			return dev_err_probe(dev, ret, "Failed to enable accelerometer and gyroscope");
   178	
   179		ret = regmap_set_bits(regmap, BMI270_ACC_CONF_REG,
Quoted 1 line

180 FIELD_PREP(BMI270_ACC_CONF_ODR_MSK,

181 BMI270_ACC_CONF_ODR_100HZ) |
182 FIELD_PREP(BMI270_ACC_CONF_BWP_MSK,
183 BMI270_ACC_CONF_BWP_NORMAL_MODE) |

   184				      BMI270_PWR_CONF_ADV_PWR_SAVE_MSK);
   185		if (ret)
   186			return dev_err_probe(dev, ret, "Failed to configure accelerometer");
   187	
   188		ret = regmap_set_bits(regmap, BMI270_GYR_CONF_REG,
   189				      FIELD_PREP(BMI270_GYR_CONF_ODR_MSK,
   190						 BMI270_GYR_CONF_ODR_200HZ) |
   191				      FIELD_PREP(BMI270_GYR_CONF_BWP_MSK,
   192						 BMI270_GYR_CONF_BWP_NORMAL_MODE) |
   193				      BMI270_PWR_CONF_ADV_PWR_SAVE_MSK);
   194		if (ret)
   195			return dev_err_probe(dev, ret, "Failed to configure gyroscope");
   196	
   197		/* Enable FIFO_WKUP, Disable ADV_PWR_SAVE and FUP_EN */
Quoted 12 lines
   198		ret = regmap_write(regmap, BMI270_PWR_CONF_REG,
   199				   BMI270_PWR_CONF_FIFO_WKUP_MSK);
   200		if (ret)
   201			return dev_err_probe(dev, ret, "Failed to set power configuration");
   202	
   203		return 0;
   204	}
   205	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

I am having trouble reproducing this build error on both jic23-iio/togreg and linus/master v6.11.rc7 on an aarch64 box with the same compiler version. Maybe a config option is causing this?

However, I will add #include <linux/bitfield.h> to remedy this issue if some edge case is being hit.

Best regards,
Alex

#8 lore raw
In reply to Alex Lanzano

Hi Alex!

I recently received a review for the code for the BMP280 sensors, and I think it applies well to you as well. Since you are using the sleeping functions in your code, maybe a comment on top that explains why this value or where you found it in the datasheet would be helpful.

Specifically for the Bosch Sensors, because Bosch's datasheets have either hidden or no information at all, and you need to search for stuff in the respective C sensor API in the Bosch GitHub.

Cheers,
Vasilis

author maintainer
#9 lore raw
Quoted 10 lines · Vasileios Amoiridis

Hi Alex!

I recently received a review for the code for the BMP280 sensors, and I think it applies well to you as well. Since you are using the sleeping functions in your code, maybe a comment on top that explains why this value or where you found it in the datasheet would be helpful.

Specifically for the Bosch Sensors, because Bosch's datasheets have either hidden or no information at all, and you need to search for stuff in the respective C sensor API in the Bosch GitHub.

Thanks for the review! I'll be sure to comment the sleeping functions.

Best regards,
Alex