Skip to contentSkip to conversation

Add support for Bosch BNO055 IMU

PATCH In review [email protected] 6 participants 26 messages Sep 7, 2022 – Sep 23, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v7 cover Add support for Bosch BNO055 IMU

From: Andrea Merello <[email protected]>

This series (tries to) add support for Bosch BNO055 IMU to Linux IIO subsystem. It is made up several patches:

1/14 to 6/14: add some IIO modifiers, and their documentation, to the IIO
core layer, in order to being able to expose the linear acceleration and Euler angles among standard attributes. Also update the IIO event monitor tool

7/14: fix binary attributes didn't work with IIO

8/14 to 11/14: add the core IIO BNO055 driver and documentation for sysfs
attributes and DT bindings

12/14: adds serdev BNO055 driver to actually use the IMU via serial line

13/14: adds I2C BNO055 driver to actually use the IMU via I2C wiring

14/14: add a documentation file that describe the bno055 driver and
specifically the calibration

In this series this [1] patch has been also squashed.

Differences wrt v6:

- fix some typos.
- fix some style issues.
- get rid of ifdefs for CONFIG_DEBUG_FS.
- avoid pushing data to the IIO layer if we actually failed reading it.
- rework debugfs file creating failure path.
- fix errors and warning found by kernel test robot <[email protected]>
- rebase

Differences wrt other BNO055 drivers:

Previously at least another driver for the very same chip has been posted to the Linux ML [0], but it has been never merged, and it seems no one cared of it since quite a long time.

This driver differs from the above driver on the following aspects:

- This driver supports also serial access (to be reliable, reset pin is required to be wired)

- The above driver tried to support all IMU HW modes by allowing to choose one in the DT, and adapting IIO attributes accordingly. This driver does not rely on DT for this, instead settings are done via sysfs attributes. All IIO attributes are always exposed; more on this later on. This driver however supports only a subset of the HW-supported modes.

- This driver has some support for managing the IMU calibration

Supported operation modes:

- AMG (accelerometer, magnetometer and gyroscope) mode, which provides raw (uncalibrated) measurements from the said sensors, and allows for setting some parameters about them (e.g. filter cut-off frequency, max sensor ranges, etc).

- Fusion mode, which still provides AMG measures, while it also provides other data calculated by the IMU (e.g. rotation angles, linear acceleration, etc). In this mode user has no freedom to set any sensor parameter, since the HW locks them. Autocalibration and correction is performed by the IMU.

IIO attributes exposing sensors parameters are always present, but in fusion modes the available values are constrained to just the one used by the HW. This is reflected in the '*_available' IIO attributes.

Trying to set a not-supported value always falls back to the closest supported one, which in this case is just the one in use by the HW.

IIO attributes for unavailable measurements (e.g. Euler angles in AMG mode) can't be read (return -EBUSY, or refuse to enable buffer).

IMU calibration:

The IMU supports for two sets of calibration parameters:

- SIC matrix. user-provided; this driver doesn't currently support it

- Offset and radius parameters. The IMU automatically finds out them when it is running in fusion mode; supported by this driver.

The driver provides access to autocalibration flags (i.e. you can known if the IMU has successfully autocalibrated) and to calibration data blob. The user can save this blob in a "firmware" file (i.e. in /lib/firmware) that the driver looks for at probe time. If found, then the IMU is initialized with this calibration data. This saves the user from performing the calibration procedure every time (which consist of moving the IMU in various way).

The driver looks for calibration data file using two different names:
first a file whose name is suffixed with the IMU unique ID is searched for; this is useful when there is more than one IMU instance. If this file is not found, then a "generic" calibration file is searched for (which can be used when only one IMU is present, without struggling with fancy names, that changes on each device).

In AMG mode the IIO 'offset' attributes provide access to the offsets from calibration data (if any), so that the user can apply them to the accel, angvel and magn IIO attributes. In fusion mode they are not needed and read as zero.

Access protocols and serdev module:

The serial protocol is quite simple, but there are tricks to make it really works. Those tricks and workarounds are documented in the driver source file.

The core BNO055 driver tries to group readings in burst when appropriate, in order to optimize triggered buffer operation. The threshold for splitting a burst (i.e. max number of unused bytes in the middle of a burst that will be throw away) is provided to the core driver by the lowlevel access driver (either serdev or I2C) at probe time.

[0] https://www.spinics.net/lists/linux-iio/msg25508.html
[1] https://lore.kernel.org/lkml/[email protected]/

Andrea Merello (14):
iio: add modifiers for linear acceleration
iio: document linear acceleration modifiers
iio: event_monitor: add linear acceleration modifiers
iio: add modifers for pitch, yaw, roll
iio: document pitch, yaw, roll modifiers
iio: event_monitor: add pitch, yaw and roll modifiers
iio: add support for binary attributes
iio: imu: add Bosch Sensortec BNO055 core driver
iio: document bno055 private sysfs attributes
iio: document "serialnumber" sysfs attribute
dt-bindings: iio/imu: Add Bosch BNO055
iio: imu: add BNO055 serdev driver
iio: imu: add BNO055 I2C driver
docs: iio: add documentation for BNO055 driver

 Documentation/ABI/testing/sysfs-bus-iio       |   25 +
 .../ABI/testing/sysfs-bus-iio-bno055          |   81 +
 .../bindings/iio/imu/bosch,bno055.yaml        |   59 +
 Documentation/iio/bno055.rst                  |   51 +
 Documentation/iio/index.rst                   |    2 +
 drivers/iio/imu/Kconfig                       |    1 +
 drivers/iio/imu/Makefile                      |    1 +
 drivers/iio/imu/bno055/Kconfig                |   25 +
 drivers/iio/imu/bno055/Makefile               |   10 +
 drivers/iio/imu/bno055/bno055.c               | 1698 +++++++++++++++++
 drivers/iio/imu/bno055/bno055.h               |   13 +
 drivers/iio/imu/bno055/bno055_i2c.c           |   57 +
 drivers/iio/imu/bno055/bno055_ser_core.c      |  560 ++++++
 drivers/iio/imu/bno055/bno055_ser_trace.c     |   14 +
 drivers/iio/imu/bno055/bno055_ser_trace.h     |  104 +
 drivers/iio/industrialio-core.c               |   10 +-
 include/uapi/linux/iio/types.h                |    7 +-
 tools/iio/iio_event_monitor.c                 |    6 +
 18 files changed, 2722 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-bno055
 create mode 100644 Documentation/devicetree/bindings/iio/imu/bosch,bno055.yaml
 create mode 100644 Documentation/iio/bno055.rst
 create mode 100644 drivers/iio/imu/bno055/Kconfig
 create mode 100644 drivers/iio/imu/bno055/Makefile
 create mode 100644 drivers/iio/imu/bno055/bno055.c
 create mode 100644 drivers/iio/imu/bno055/bno055.h
 create mode 100644 drivers/iio/imu/bno055/bno055_i2c.c
 create mode 100644 drivers/iio/imu/bno055/bno055_ser_core.c
 create mode 100644 drivers/iio/imu/bno055/bno055_ser_trace.c
 create mode 100644 drivers/iio/imu/bno055/bno055_ser_trace.h

--
2.17.1

#1 lore raw

PATCH v7 1/14 iio: add modifiers for linear acceleration

From: Andrea Merello <[email protected]>

Add IIO_MOD_LINEAR_X, IIO_MOD_LINEAR_Y and IIO_MOD_LINEAR_Z modifiers to te IIO core, which is preparatory for adding the Bosch BNO055 IMU driver.

Bosch BNO055 IMU can report raw accelerations (among x, y and z axis) as well as the so called "linear accelerations" (again, among x, y and z axis) which is basically the acceleration after subtracting gravity and for which those new modifiers are for.

---
 drivers/iio/industrialio-core.c | 3 +++
 include/uapi/linux/iio/types.h  | 4 +++-
 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/iio/industrialio-core.c +3 -0
index d38623c046cc..37f7e231fce2 100644
@@ -134,6 +134,9 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_ETHANOL] = "ethanol",
 	[IIO_MOD_H2] = "h2",
 	[IIO_MOD_O2] = "o2",
+	[IIO_MOD_LINEAR_X] = "linear_x",
+	[IIO_MOD_LINEAR_Y] = "linear_y",
+	[IIO_MOD_LINEAR_Z] = "linear_z",
 };
 
 /* relies on pairs of these shared then separate */
include/uapi/linux/iio/types.h +3 -1
index 472cead10d8d..0993f6b697fc 100644
@@ -95,6 +95,9 @@ enum iio_modifier {
 	IIO_MOD_ETHANOL,
 	IIO_MOD_H2,
 	IIO_MOD_O2,
+	IIO_MOD_LINEAR_X,
+	IIO_MOD_LINEAR_Y,
+	IIO_MOD_LINEAR_Z,
 };
 
 enum iio_event_type {
@@ -115,4 +118,3 @@ enum iio_event_direction {
 };
 
 #endif /* _UAPI_IIO_TYPES_H_ */
-
Signature · 1 line
2.17.1
#2 lore raw

PATCH v7 2/14 iio: document linear acceleration modifiers

In reply to [email protected]

From: Andrea Merello <[email protected]>

Introduce ABI documentation for new IIO modifiers used for reporting "linear acceleration" measures.

---
 Documentation/ABI/testing/sysfs-bus-iio | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +9 -0
index 80e8a38d1ee2..cc1fe672580f 100644
@@ -260,6 +260,15 @@ Description:
 		Has all of the equivalent parameters as per voltageY. Units
 		after application of scale and offset are m/s^2.
 
+What:		/sys/bus/iio/devices/iio:deviceX/in_accel_linear_x_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_accel_linear_y_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_accel_linear_z_raw
+KernelVersion:	6.1
+Contact:	[email protected]
+Description:
+		As per in_accel_X_raw attributes, but minus the
+		acceleration due to gravity.
+
 What:		/sys/bus/iio/devices/iio:deviceX/in_gravity_x_raw
 What:		/sys/bus/iio/devices/iio:deviceX/in_gravity_y_raw
 What:		/sys/bus/iio/devices/iio:deviceX/in_gravity_z_raw
Signature · 1 line
2.17.1
#3 lore raw

PATCH v7 3/14 iio: event_monitor: add linear acceleration modifiers

In reply to [email protected]

From: Andrea Merello <[email protected]>

Following the introduction of IIO linear acceleration modifiers, update the event_monitor tool accordingly.

---
 tools/iio/iio_event_monitor.c | 3 +++
 1 file changed, 3 insertions(+)
tools/iio/iio_event_monitor.c +3 -0
index 2f4581658859..1fee44abb836 100644
@@ -122,6 +122,9 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_PM4] = "pm4",
 	[IIO_MOD_PM10] = "pm10",
 	[IIO_MOD_O2] = "o2",
+	[IIO_MOD_LINEAR_X] = "linear_x",
+	[IIO_MOD_LINEAR_Y] = "linear_y",
+	[IIO_MOD_LINEAR_Z] = "linear_z",
 };
 
 static bool event_is_known(struct iio_event_data *event)
Signature · 1 line
2.17.1
#4 lore raw

PATCH v7 4/14 iio: add modifers for pitch, yaw, roll

In reply to [email protected]

From: Andrea Merello <[email protected]>

Add modifiers for reporting rotations as euler angles (i.e. yaw, pitch and roll).

---
 drivers/iio/industrialio-core.c | 3 +++
 include/uapi/linux/iio/types.h  | 3 +++
 2 files changed, 6 insertions(+)
drivers/iio/industrialio-core.c +3 -0
index 37f7e231fce2..9e661efb6f47 100644
@@ -137,6 +137,9 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_LINEAR_X] = "linear_x",
 	[IIO_MOD_LINEAR_Y] = "linear_y",
 	[IIO_MOD_LINEAR_Z] = "linear_z",
+	[IIO_MOD_PITCH] = "pitch",
+	[IIO_MOD_YAW] = "yaw",
+	[IIO_MOD_ROLL] = "roll",
 };
 
 /* relies on pairs of these shared then separate */
include/uapi/linux/iio/types.h +3 -0
index 0993f6b697fc..4853701ba70d 100644
@@ -98,6 +98,9 @@ enum iio_modifier {
 	IIO_MOD_LINEAR_X,
 	IIO_MOD_LINEAR_Y,
 	IIO_MOD_LINEAR_Z,
+	IIO_MOD_PITCH,
+	IIO_MOD_YAW,
+	IIO_MOD_ROLL,
 };
 
 enum iio_event_type {
Signature · 1 line
2.17.1
#5 lore raw

PATCH v7 5/14 iio: document pitch, yaw, roll modifiers

In reply to [email protected]

From: Andrea Merello <[email protected]>

Introduce ABI documentation for new modifiers used for reporting rotations expressed as euler angles (i.e. yaw, pitch, roll).

It looks like we have some unit inconsistency along various IIO modifiers:
it seems that incli is in deg, angl is in radians and rot isn't documented, but at least the adis16209 driver has rot in deg.

Here we use deg (so angl is the only one using radians).

---
 Documentation/ABI/testing/sysfs-bus-iio | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +9 -0
index cc1fe672580f..f694a3653245 100644
@@ -2077,3 +2077,12 @@ Description:
 		individual channels. If multiple channels are enabled in a scan,
 		then the sampling_frequency of the scan may be computed from the
 		per channel sampling frequencies.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_rot_yaw_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_rot_pitch_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_rot_roll_raw
+KernelVersion:	6.1
+Contact:	[email protected]
+Description:
+		Raw (unscaled) euler angles readings. Units after
+		application of scale are deg.
Signature · 1 line
2.17.1
#6 lore raw

PATCH v7 6/14 iio: event_monitor: add pitch, yaw and roll modifiers

In reply to [email protected]

From: Andrea Merello <[email protected]>

Following the introduction of pitch, yaw and roll IIO modifiers, update the event_monitor tool accordingly.

---
 tools/iio/iio_event_monitor.c | 3 +++
 1 file changed, 3 insertions(+)
tools/iio/iio_event_monitor.c +3 -0
index 1fee44abb836..ee3f78c47655 100644
@@ -125,6 +125,9 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_LINEAR_X] = "linear_x",
 	[IIO_MOD_LINEAR_Y] = "linear_y",
 	[IIO_MOD_LINEAR_Z] = "linear_z",
+	[IIO_MOD_PITCH] = "pitch",
+	[IIO_MOD_YAW] = "yaw",
+	[IIO_MOD_ROLL] = "roll",
 };
 
 static bool event_is_known(struct iio_event_data *event)
Signature · 1 line
2.17.1
#7 lore raw

PATCH v7 7/14 iio: add support for binary attributes

In reply to [email protected]

From: Andrea Merello <[email protected]>

When a IIO device is registered, the IIO core creates an attribute group on its own, where it puts the channel attributes, and where it copies the attributes in indio_dev->info->attrs.

Unfortunately it doesn't take care of binary attributes (i.e. it only consider indio_dev->info->attrs->attrs, and it ignores indio_dev->info->attrs->bin_attrs).

Fix this by making the IIO layer take care also of the binary attributes.

Note that while it is necessary to copy the non-binary attributes because the IIO layer needs more room to add the channels attribute, it should be enough to assign the bin_attrs pointer to the binary attributes pointed by indio_dev->info->attrs->bin_attrs.

---
 drivers/iio/industrialio-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/industrialio-core.c +3 -1
index 9e661efb6f47..75654cc70ede 100644
@@ -1576,7 +1576,7 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev)
 		ret = -ENOMEM;
 		goto error_clear_attrs;
 	}
-	/* Copy across original attributes */
+	/* Copy across original attributes, and point to original binary attributes */
 	if (indio_dev->info->attrs) {
 		memcpy(iio_dev_opaque->chan_attr_group.attrs,
 		       indio_dev->info->attrs->attrs,
@@ -1584,6 +1584,8 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev)
 		       *attrcount_orig);
 		iio_dev_opaque->chan_attr_group.is_visible =
 			indio_dev->info->attrs->is_visible;
+		iio_dev_opaque->chan_attr_group.bin_attrs =
+			indio_dev->info->attrs->bin_attrs;
 	}
 	attrn = attrcount_orig;
 	/* Add all elements from the list. */
Signature · 1 line
2.17.1
#8 lore raw

PATCH v7 8/14 iio: imu: add Bosch Sensortec BNO055 core driver

In reply to [email protected]

From: Andrea Merello <[email protected]>

Add the core driver for the BNO055 IMU from Bosch. This IMU can be connected via both serial and I2C busses; separate patches will add support for them.

The driver supports "AMG" (Accelerometer, Magnetometer, Gyroscope) mode, that provides raw data from the said internal sensors, and a couple of "fusion" modes (i.e. the IMU also does calculations in order to provide euler angles, quaternions, linear acceleration and gravity measurements).

In fusion modes the AMG data is still available (with some calibration refinements done by the IMU), but certain settings such as low pass filters cut-off frequency and sensors' ranges are fixed, while in AMG mode they can be customized; this is why AMG mode can still be interesting.

---
 drivers/iio/imu/Kconfig         |    1 +
 drivers/iio/imu/Makefile        |    1 +
 drivers/iio/imu/bno055/Kconfig  |    4 +
 drivers/iio/imu/bno055/Makefile |    3 +
 drivers/iio/imu/bno055/bno055.c | 1698 +++++++++++++++++++++++++++++++
 drivers/iio/imu/bno055/bno055.h |   13 +
 6 files changed, 1720 insertions(+)
 create mode 100644 drivers/iio/imu/bno055/Kconfig
 create mode 100644 drivers/iio/imu/bno055/Makefile
 create mode 100644 drivers/iio/imu/bno055/bno055.c
 create mode 100644 drivers/iio/imu/bno055/bno055.h
drivers/iio/imu/Kconfig +1 -0
index 001ca2c3ff95..f1d7d4b5e222 100644
@@ -52,6 +52,7 @@ config ADIS16480
 	  ADIS16485, ADIS16488 inertial sensors.
 
 source "drivers/iio/imu/bmi160/Kconfig"
+source "drivers/iio/imu/bno055/Kconfig"
 
 config FXOS8700
 	tristate
drivers/iio/imu/Makefile +1 -0
index c82748096c77..6eb612034722 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 += bno055/
 
 obj-$(CONFIG_FXOS8700) += fxos8700_core.o
 obj-$(CONFIG_FXOS8700_I2C) += fxos8700_i2c.o
drivers/iio/imu/bno055/Kconfig new file +4 -0
new file mode 100644
index 000000000000..467bc0ed22f8
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config BOSCH_BNO055
+	tristate
drivers/iio/imu/bno055/Makefile new file +3 -0
new file mode 100644
index 000000000000..0a682ade510c
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_BOSCH_BNO055) += bno055.o
drivers/iio/imu/bno055/bno055.c new file +1698 -0

1,698 lines not on this page · raw message

drivers/iio/imu/bno055/bno055.h new file +13 -0
new file mode 100644
index 000000000000..64f9fc95cebc
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef __BNO055_H__
+#define __BNO055_H__
+
+#include <linux/regmap.h>
+#include <linux/types.h>
+
+struct device;
+int bno055_probe(struct device *dev, struct regmap *regmap,
+		 int xfer_burst_break_thr, bool sw_reset);
+extern const struct regmap_config bno055_regmap_config;
+
+#endif
Signature · 1 line
2.17.1
maintainer
#9 lore raw

Re: [v7 08/14] iio: imu: add Bosch Sensortec BNO055 core driver

Quoted 11 lines · On Wed, 7 Sep 2022 15:21:59 +0200 <[email protected]> wrote:

From: Andrea Merello <[email protected]>

Add the core driver for the BNO055 IMU from Bosch. This IMU can be connected via both serial and I2C busses; separate patches will add support for them.

The driver supports "AMG" (Accelerometer, Magnetometer, Gyroscope) mode, that provides raw data from the said internal sensors, and a couple of "fusion" modes (i.e. the IMU also does calculations in order to provide euler angles, quaternions, linear acceleration and gravity measurements).

Quoted 6 lines

In fusion modes the AMG data is still available (with some calibration refinements done by the IMU), but certain settings such as low pass filters cut-off frequency and sensors' ranges are fixed, while in AMG mode they can be customized; this is why AMG mode can still be interesting.

Hi Andrea,

I think this is looking to be in a good state now.
There is some devm handling for clks now available that should avoid the need to open code that here.

I've made that change whilst applying. Please take a look to make sure I didn't mess it up!

Jonathan

Quoted 9 lines
drivers/iio/imu/bno055/bno055.c new file +9 -0
+
+static void bno055_clk_disable(void *arg)
+{
+	clk_disable_unprepare(arg);
+}
+
+int bno055_probe(struct device *dev, struct regmap *regmap,
+		 int xfer_burst_break_thr, bool sw_reset)
+{

...

Quoted 5 lines
drivers/iio/imu/bno055/bno055.c new file +5 -0
+	priv->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(priv->reset_gpio))
+		return dev_err_probe(dev, PTR_ERR(priv->reset_gpio), "Failed to get reset GPIO\n");
+
+	priv->clk = devm_clk_get_optional(dev, "clk");

drivers/iio/imu/bno055/bno055.c

Quoted 10 lines
drivers/iio/imu/bno055/bno055.c new file +10 -0
+	if (IS_ERR(priv->clk))
+		return dev_err_probe(dev, PTR_ERR(priv->clk), "Failed to get CLK\n");
+
+	ret = clk_prepare_enable(priv->clk);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(dev, bno055_clk_disable, priv->clk);
+	if (ret)
+		return ret;#

devm_clk_get_optional_enabled() is now available and should work here I think?

Quoted 8 lines
drivers/iio/imu/bno055/bno055.c new file +8 -0
+
+	if (priv->reset_gpio) {
+		usleep_range(5000, 10000);
+		gpiod_set_value_cansleep(priv->reset_gpio, 1);
+		usleep_range(650000, 750000);
+	} else if (!sw_reset) {
+		dev_warn(dev, "No usable reset method; IMU may be unreliable\n");
+	}
#10 lore raw

Re: [v7 08/14] iio: imu: add Bosch Sensortec BNO055 core driver

Il giorno dom 18 set 2022 alle ore 19:27 Jonathan Cameron <[email protected]> ha scritto:

[...]

Quoted 9 lines

Hi Andrea,

I think this is looking to be in a good state now.
There is some devm handling for clks now available that should avoid the need to open code that here.

I've made that change whilst applying. Please take a look to make sure I didn't mess it up!

Hi, thank you for directly fixing, so that I can avoid a further series version :)

I've looked at this change, and it looks good to me; also, I've run some tests and nothing failed.

Andrea

Quoted 40 lines

Jonathan

Quoted 9 lines
drivers/iio/imu/bno055/bno055.c new file +9 -0
+
+static void bno055_clk_disable(void *arg)
+{
+     clk_disable_unprepare(arg);
+}
+
+int bno055_probe(struct device *dev, struct regmap *regmap,
+              int xfer_burst_break_thr, bool sw_reset)
+{

...

Quoted 5 lines
drivers/iio/imu/bno055/bno055.c new file +5 -0
+     priv->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+     if (IS_ERR(priv->reset_gpio))
+             return dev_err_probe(dev, PTR_ERR(priv->reset_gpio), "Failed to get reset GPIO\n");
+
+     priv->clk = devm_clk_get_optional(dev, "clk");

drivers/iio/imu/bno055/bno055.c

Quoted 10 lines
drivers/iio/imu/bno055/bno055.c new file +10 -0
+     if (IS_ERR(priv->clk))
+             return dev_err_probe(dev, PTR_ERR(priv->clk), "Failed to get CLK\n");
+
+     ret = clk_prepare_enable(priv->clk);
+     if (ret)
+             return ret;
+
+     ret = devm_add_action_or_reset(dev, bno055_clk_disable, priv->clk);
+     if (ret)
+             return ret;#

devm_clk_get_optional_enabled() is now available and should work here I think?

Quoted 8 lines
drivers/iio/imu/bno055/bno055.c new file +8 -0
+
+     if (priv->reset_gpio) {
+             usleep_range(5000, 10000);
+             gpiod_set_value_cansleep(priv->reset_gpio, 1);
+             usleep_range(650000, 750000);
+     } else if (!sw_reset) {
+             dev_warn(dev, "No usable reset method; IMU may be unreliable\n");
+     }
#11 lore raw

PATCH v7 9/14 iio: document bno055 private sysfs attributes

In reply to [email protected]

From: Andrea Merello <[email protected]>

Add ABI documentation for bno055 driver private sysfs attributes.

---
 .../ABI/testing/sysfs-bus-iio-bno055          | 81 +++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-bno055
Documentation/ABI/testing/sysfs-bus-iio-bno055 new file +81 -0
new file mode 100644
index 000000000000..f32b1644e986
@@ -0,0 +1,81 @@
+What:		/sys/bus/iio/devices/iio:deviceX/in_accel_raw_range
+KernelVersion:	6.1
+Contact:	[email protected]
+Description:
+		Raw (unscaled) range for acceleration readings. Unit after
+		application of scale is m/s^2. Note that this doesn't affects
+		the scale (which should be used when changing the maximum and
+		minimum readable value affects also the reading scaling factor).
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_anglvel_raw_range
+KernelVersion:	6.1
+Contact:	[email protected]
+Description:
+		Range for angular velocity readings in radians per second. Note
+		that this does not affects the scale (which should be used when
+		changing the maximum and minimum readable value affects also the
+		reading scaling factor).
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_accel_raw_range_available
+KernelVersion:	6.1
+Contact:	[email protected]
+Description:
+		List of allowed values for in_accel_raw_range attribute
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_anglvel_raw_range_available
+KernelVersion:	6.1
+Contact:	[email protected]
+Description:
+		List of allowed values for in_anglvel_raw_range attribute
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_magn_calibration_fast_enable
+KernelVersion:	6.1
+Contact:	[email protected]
+Description:
+		Can be 1 or 0. Enables/disables the "Fast Magnetometer
+		Calibration" HW function.
+
+What:		/sys/bus/iio/devices/iio:deviceX/fusion_enable
+KernelVersion:	6.1
+Contact:	[email protected]
+Description:
+		Can be 1 or 0. Enables/disables the "sensor fusion" (a.k.a.
+		NDOF) HW function.
+
+What:		/sys/bus/iio/devices/iio:deviceX/calibration_data
+KernelVersion:	6.1
+Contact:	[email protected]
+Description:
+		Reports the binary calibration data blob for the IMU sensors.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_accel_calibration_auto_status
+KernelVersion:	6.1
+Contact:	[email protected]
+Description:
+		Reports the autocalibration status for the accelerometer sensor.
+		Can be 0 (calibration non even enabled) or 1 to 5 where the greater
+		the number, the better the calibration status.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_gyro_calibration_auto_status
+KernelVersion:	6.1
+Contact:	[email protected]
+Description:
+		Reports the autocalibration status for the gyroscope sensor.
+		Can be 0 (calibration non even enabled) or 1 to 5 where the greater
+		the number, the better the calibration status.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_magn_calibration_auto_status
+KernelVersion:	6.1
+Contact:	[email protected]
+Description:
+		Reports the autocalibration status for the magnetometer sensor.
+		Can be 0 (calibration non even enabled) or 1 to 5 where the greater
+		the number, the better the calibration status.
+
+What:		/sys/bus/iio/devices/iio:deviceX/sys_calibration_auto_status
+KernelVersion:	6.1
+Contact:	[email protected]
+Description:
+		Reports the status for the IMU overall autocalibration.
+		Can be 0 (calibration non even enabled) or 1 to 5 where the greater
+		the number, the better the calibration status.
Signature · 1 line
2.17.1
#12 lore raw

PATCH v7 10/14 iio: document "serialnumber" sysfs attribute

In reply to [email protected]

From: Andrea Merello <[email protected]>

Add ABI documentation for the new "serialnumber" sysfs attribute. The first user is the bno055 IIO driver.

---
 Documentation/ABI/testing/sysfs-bus-iio | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +7 -0
index f694a3653245..429c8cb2674c 100644
@@ -2086,3 +2086,10 @@ Contact:	[email protected]
 Description:
 		Raw (unscaled) euler angles readings. Units after
 		application of scale are deg.
+
+What:		/sys/bus/iio/devices/iio:deviceX/serialnumber
+KernelVersion:	6.1
+Contact:	[email protected]
+Description:
+		An example format is 16-bytes, 2-digits-per-byte, HEX-string
+		representing the sensor unique ID number.
Signature · 1 line
2.17.1
#13 lore raw

PATCH v7 11/14 dt-bindings: iio/imu: Add Bosch BNO055

In reply to [email protected]

From: Andrea Merello <[email protected]>

Introduce new documentation file for the Bosch BNO055 IMU.

---
 .../bindings/iio/imu/bosch,bno055.yaml        | 59 +++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/bosch,bno055.yaml
Documentation/devicetree/bindings/iio/imu/bosch,bno055.yaml new file +59 -0
new file mode 100644
index 000000000000..e0d06db161a9
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/imu/bosch,bno055.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Bosch BNO055
+
+maintainers:
+  - Andrea Merello <[email protected]>
+
+description: |
+  Inertial Measurement Unit with Accelerometer, Gyroscope, Magnetometer and
+  internal MCU for sensor fusion
+  https://www.bosch-sensortec.com/products/smart-sensors/bno055/
+
+properties:
+  compatible:
+    enum:
+      - bosch,bno055
+
+  reg:
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+required:
+  - compatible
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    serial {
+      imu {
+        compatible = "bosch,bno055";
+        reset-gpios = <&gpio0 54 GPIO_ACTIVE_LOW>;
+        clocks = <&imu_clk>;
+      };
+    };
+
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      imu@28 {
+        compatible = "bosch,bno055";
+        reg = <0x28>;
+        reset-gpios = <&gpio0 54 GPIO_ACTIVE_LOW>;
+        clocks = <&imu_clk>;
+      };
+    };
Signature · 1 line
2.17.1
#14 lore raw

PATCH v7 12/14 iio: imu: add BNO055 serdev driver

In reply to [email protected]

From: Andrea Merello <[email protected]>

Add a serdev driver for communicating to a BNO055 IMU via serial bus, and enable the BNO055 core driver to work in this scenario.

---
 drivers/iio/imu/bno055/Kconfig            |  10 +
 drivers/iio/imu/bno055/Makefile           |   5 +
 drivers/iio/imu/bno055/bno055_ser_core.c  | 560 ++++++++++++++++++++++
 drivers/iio/imu/bno055/bno055_ser_trace.c |  14 +
 drivers/iio/imu/bno055/bno055_ser_trace.h | 104 ++++
 5 files changed, 693 insertions(+)
 create mode 100644 drivers/iio/imu/bno055/bno055_ser_core.c
 create mode 100644 drivers/iio/imu/bno055/bno055_ser_trace.c
 create mode 100644 drivers/iio/imu/bno055/bno055_ser_trace.h
drivers/iio/imu/bno055/Kconfig +10 -0
index 467bc0ed22f8..b51d63b49ea4 100644
@@ -2,3 +2,13 @@
 
 config BOSCH_BNO055
 	tristate
+
+config BOSCH_BNO055_SERIAL
+	tristate "Bosch BNO055 attached via UART"
+	depends on SERIAL_DEV_BUS
+	select BOSCH_BNO055
+	help
+	  Enable this to support Bosch BNO055 IMUs attached via UART.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called bno055_sl.
drivers/iio/imu/bno055/Makefile +5 -0
index 0a682ade510c..ef9219563782 100644
@@ -1,3 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_BOSCH_BNO055) += bno055.o
+obj-$(CONFIG_BOSCH_BNO055_SERIAL) += bno055_ser.o
+bno055_ser-y := bno055_ser_core.o
+# define_trace.h needs to know how to find our header
+CFLAGS_bno055_ser_trace.o := -I$(src)
+bno055_ser-$(CONFIG_TRACING) += bno055_ser_trace.o
drivers/iio/imu/bno055/bno055_ser_core.c new file +560 -0

560 lines not on this page · raw message

drivers/iio/imu/bno055/bno055_ser_trace.c new file +14 -0
new file mode 100644
index 000000000000..48397b66daef
@@ -0,0 +1,14 @@
+//SPDX-License-Identifier: GPL-2.0
+
+/*
+ * bno055_ser Trace Support
+ * Copyright (C) 2022 Istituto Italiano di Tecnologia
+ * Electronic Design Laboratory
+ *
+ * Based on:
+ *   Device core Trace Support
+ *   Copyright (C) 2021, Intel Corporation
+ */
+
+#define CREATE_TRACE_POINTS
+#include "bno055_ser_trace.h"
drivers/iio/imu/bno055/bno055_ser_trace.h new file +104 -0

104 lines not on this page · raw message

Signature · 1 line
2.17.1
#15 lore raw

PATCH v7 13/14 iio: imu: add BNO055 I2C driver

In reply to [email protected]

From: Andrea Merello <[email protected]>

Add an I2C driver for communicating to a BNO055 IMU via I2C bus and enable the BNO055 core driver to work in this scenario.

---
 drivers/iio/imu/bno055/Kconfig      | 11 ++++++
 drivers/iio/imu/bno055/Makefile     |  2 +
 drivers/iio/imu/bno055/bno055_i2c.c | 57 +++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+)
 create mode 100644 drivers/iio/imu/bno055/bno055_i2c.c
drivers/iio/imu/bno055/Kconfig +11 -0
index b51d63b49ea4..fa79b1ac4f85 100644
@@ -12,3 +12,14 @@ config BOSCH_BNO055_SERIAL
 
 	  This driver can also be built as a module. If so, the module will be
 	  called bno055_sl.
+
+config BOSCH_BNO055_I2C
+	tristate "Bosch BNO055 attached via I2C bus"
+	depends on I2C
+	select REGMAP_I2C
+	select BOSCH_BNO055
+	help
+	  Enable this to support Bosch BNO055 IMUs attached via I2C bus.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called bno055_i2c.
drivers/iio/imu/bno055/Makefile +2 -0
index ef9219563782..98c624730dae 100644
@@ -6,3 +6,5 @@ bno055_ser-y := bno055_ser_core.o
 # define_trace.h needs to know how to find our header
 CFLAGS_bno055_ser_trace.o := -I$(src)
 bno055_ser-$(CONFIG_TRACING) += bno055_ser_trace.o
+
+obj-$(CONFIG_BOSCH_BNO055_I2C) += bno055_i2c.o
drivers/iio/imu/bno055/bno055_i2c.c new file +57 -0

57 lines not on this page · raw message

Signature · 1 line
2.17.1
#16 lore raw

Re: [v7 13/14] iio: imu: add BNO055 I2C driver

Quoted 9 lines · On Wed, Sep 7, 2022 at 4:22 PM <[email protected]> wrote:

From: Andrea Merello <[email protected]>

Add an I2C driver for communicating to a BNO055 IMU via I2C bus and enable the BNO055 core driver to work in this scenario.

Hmm... It has my tag but I have noticed something to improve.

...

Quoted 1 line

+#define BNO055_I2C_XFER_BURST_BREAK_THRESHOLD 3 /* FIXME */

Can we elaborate what to fix and why it can't be fixed right now?

...

drivers/iio/imu/bno055/bno055_i2c.c line 40

Quoted 4 lines
drivers/iio/imu/bno055/bno055_i2c.c new file +3 -0
+static const struct of_device_id __maybe_unused bno055_i2c_of_match[] = {
+       { .compatible = "bosch,bno055" },
 
+       { },

No comma for the terminator entry.

Quoted 1 line

+};

...

Quoted 1 line

+ .of_match_table = of_match_ptr(bno055_i2c_of_match),

No of_match_ptr(). This will disable ACPI support along with potential compiler warning.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#17 lore raw

Re: [v7 13/14] iio: imu: add BNO055 I2C driver

Quoted 1 line

Hmm... It has my tag but I have noticed something to improve.

One comment below, OK for the rest.

Quoted 5 lines

...

Quoted 1 line

+#define BNO055_I2C_XFER_BURST_BREAK_THRESHOLD 3 /* FIXME */

Can we elaborate what to fix and why it can't be fixed right now?

Ah, this is a stale comment; I'll drop it..

maintainer
#18 lore raw

Re: [v7 13/14] iio: imu: add BNO055 I2C driver

Quoted 11 lines · On Thu, 8 Sep 2022 08:42:01 +0200 Andrea Merello <[email protected]>…
Quoted 1 line

Hmm... It has my tag but I have noticed something to improve.

One comment below, OK for the rest.

Quoted 5 lines

...

Quoted 1 line

+#define BNO055_I2C_XFER_BURST_BREAK_THRESHOLD 3 /* FIXME */

Can we elaborate what to fix and why it can't be fixed right now?

Ah, this is a stale comment; I'll drop it..

I fixed up Andy's comments on this patch whilst applying.

Thanks,

Jonathan

#19 lore raw

PATCH v7 14/14 docs: iio: add documentation for BNO055 driver

In reply to [email protected]

From: Andrea Merello <[email protected]>

The bno055 driver is rather complex and have some oddities and not-obvious things that worth to document (e.g. calibration files).

This patch also contains this [0] fix squashed in.

[0] https://lore.kernel.org/lkml/[email protected]/

---
 Documentation/iio/bno055.rst | 51 ++++++++++++++++++++++++++++++++++++
 Documentation/iio/index.rst  |  2 ++
 2 files changed, 53 insertions(+)
 create mode 100644 Documentation/iio/bno055.rst
Documentation/iio/bno055.rst new file +51 -0
new file mode 100644
index 000000000000..9a489a79d8f5
@@ -0,0 +1,51 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==============================
+BNO055 driver
+==============================
+
+1. Overview
+===========
+
+This driver supports Bosch BNO055 IMUs (on both serial and I2C busses).
+
+Accelerometer, magnetometer and gyroscope measures are always provided.
+When "fusion_enable" sysfs attribute is set to 1, orientation (both Euler
+angles and quaternion), linear velocity and gravity vector are also
+provided, but some sensor settings (e.g. low pass filtering and range)
+became locked (the IMU firmware controls them).
+
+This driver supports also IIO buffers.
+
+2. Calibration
+==============
+
+The IMU continuously performs an autocalibration procedure if (and only if)
+operating in fusion mode. The magnetometer autocalibration can however be
+disabled writing 0 in the sysfs in_magn_calibration_fast_enable attribute.
+
+The driver provides access to autocalibration flags (i.e. you can known if
+the IMU has successfully autocalibrated) and to the calibration data blob.
+
+The user can save this blob in a firmware file (i.e. in /lib/firmware) that
+the driver looks for at probe time. If found, then the IMU is initialized
+with this calibration data. This saves the user from performing the
+calibration procedure every time (which consist of moving the IMU in
+various way).
+
+The driver looks for calibration data file using two different names: first
+a file whose name is suffixed with the IMU unique ID (exposed in sysfs as
+serial_number) is searched for; this is useful when there is more than one
+IMU instance. If this file is not found, then a "generic" calibration file
+is searched for (which can be used when only one IMU is present, without
+struggling with fancy names, that change on each device).
+
+Valid calibration file names would be e.g.
+ bno055-caldata-0e7c26a33541515120204a35342b04ff.dat
+ bno055-caldata.dat
+
+In non-fusion mode the IIO 'offset' attributes provide access to the
+offsets from calibration data (if any), so that the user can apply them to
+the accel, angvel and magn IIO attributes. In fusion mode they are not
+needed (the IMU firmware internally applies those corrections) and they
+read as zero.
Documentation/iio/index.rst +2 -0
index 58b7a4ebac51..1b7292c58cd0 100644
@@ -10,3 +10,5 @@ Industrial I/O
    iio_configfs
 
    ep93xx_adc
+
+   bno055
Signature · 1 line
2.17.1
#20 lore raw
In reply to [email protected]
Quoted 5 lines · On Wed, Sep 7, 2022 at 4:22 PM <[email protected]> wrote:

From: Andrea Merello <[email protected]>

This series (tries to) add support for Bosch BNO055 IMU to Linux IIO subsystem. It is made up several patches:

These

Quoted 3 lines

iio: imu: add Bosch Sensortec BNO055 core driver

iio: imu: add BNO055 serdev driver

are huge and I will look at them later on.

--
With Best Regards,
Andy Shevchenko

maintainer
#21 lore raw
Quoted 8 lines · On Wed, 7 Sep 2022 17:12:09 +0300 Andy Shevchenko <[email protected]>…
Quoted 5 lines · On Wed, Sep 7, 2022 at 4:22 PM <[email protected]> wrote:

From: Andrea Merello <[email protected]>

This series (tries to) add support for Bosch BNO055 IMU to Linux IIO subsystem. It is made up several patches:

Quoted 8 lines

These

Quoted 3 lines

iio: imu: add Bosch Sensortec BNO055 core driver

iio: imu: add BNO055 serdev driver

are huge and I will look at them later on.

I've taken another look at those and think that anything that comes up should be minor enough we should fix / tidy up as follow on patches.

I'd like to get this some build coverage as it's big and complex. Hence I've applied it to the togreg branch of iio.git / pushed out as testing.

More comments still welcome! Andy, if you get time to look at those two large patches, that would still be great + thanks for all your work reviewing this series and in general - it's a great help to me in keeping up with things.

Note I'll be rebasing that tree in the near future to get some dependencies for other sets.

Andrea, nice work getting support in place for this complex / buggy / messy device :)

Jonathan

Quoted 3 lines

--
With Best Regards,
Andy Shevchenko

#22 lore raw
In reply to [email protected]
Quoted 9 lines · On 9/7/22 20:21, [email protected] wrote:

Differences wrt v6:

- fix some typos.
- fix some style issues.
- get rid of ifdefs for CONFIG_DEBUG_FS.
- avoid pushing data to the IIO layer if we actually failed reading it.
- rework debugfs file creating failure path.
- fix errors and warning found by kernel test robot <[email protected]>
- rebase

Rebased on what tree (and what commit)? I can't cleanly apply patch [05/14].

Thanks.

Signature · 1 line
An old man doll... just what I always wanted! - Clara
#23 lore raw

Il giorno gio 8 set 2022 alle ore 05:47 Bagas Sanjaya <[email protected]> ha scritto:

Quoted 12 lines · On 9/7/22 20:21, [email protected] wrote:
Quoted 9 lines

Differences wrt v6:

- fix some typos.
- fix some style issues.
- get rid of ifdefs for CONFIG_DEBUG_FS.
- avoid pushing data to the IIO layer if we actually failed reading it.
- rework debugfs file creating failure path.
- fix errors and warning found by kernel test robot <[email protected]>
- rebase

Quoted 2 lines

Rebased on what tree (and what commit)? I can't cleanly apply patch [05/14].

Sorry, it looks like I've raced against recent updates on iio-togreg branch (i.e. I've rebased, then I've got preemped by something else, then I've tested and sent the series some days later - I should have rebased again).

BTW patches can be applied on the top of this
https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/commit/?h=togreg&id=2bc9cd66eb25d0fefbb081421d6586495e25840e

I'll prepare a v8 anyway.

Quoted 4 lines

Thanks.

--
An old man doll... just what I always wanted! - Clara

#24 lore raw
Quoted 8 lines · Andrea Merello
Quoted 2 lines

Rebased on what tree (and what commit)? I can't cleanly apply patch [05/14].

Sorry, it looks like I've raced against recent updates on iio-togreg branch (i.e. I've rebased, then I've got preemped by something else, then I've tested and sent the series some days later - I should have rebased again).

Quoted 5 lines

BTW patches can be applied on the top of this
https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/commit/?h=togreg&id=2bc9cd66eb25d0fefbb081421d6586495e25840e

I'll prepare a v8 anyway.

OK.

Don't forget to pass --base to git-format-patch(1) when preparing v8.

Signature · 1 line
An old man doll... just what I always wanted! - Clara
#25 lore raw
Quoted 9 lines · On Thu, 8 Sep 2022 14:32:49 +0700 Bagas Sanjaya <[email protected]> wrote:
Quoted 8 lines · Andrea Merello
Quoted 2 lines

Rebased on what tree (and what commit)? I can't cleanly apply patch [05/14].

Sorry, it looks like I've raced against recent updates on iio-togreg branch (i.e. I've rebased, then I've got preemped by something else, then I've tested and sent the series some days later - I should have rebased again).

Quoted 4 lines
Quoted 4 lines

BTW patches can be applied on the top of this
https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/commit/?h=togreg&id=2bc9cd66eb25d0fefbb081421d6586495e25840e

I'll prepare a v8 anyway.

For minor stuff like Doc updates, don't about rebase if everything else is fine. I can fix little merge conflicts whilst applying.

Thanks,

Jonathan

Quoted 6 lines
Quoted 1 line

OK.

Don't forget to pass --base to git-format-patch(1) when preparing v8.