Add support for Bosch BNO055 IMU
Subsystems (3)
v5 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
Differences wrt v4:
- be more tolerant wrt unrecognized chip IDs
- rename 'serial_number' attribute in 'serialnumber'
- fix missing NULL variable initialization
- use sign_extend32() instead of s16 casting where appropriate
- fix quaternion unit
- minor stuff (e.g. comments..)
- reduce (slightly) locking in serdev driver
- rework tracepoint support (e.g. remove dedicated config option)
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
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 | 50 + 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 | 1710 +++++++++++++++++ drivers/iio/imu/bno055/bno055.h | 12 + drivers/iio/imu/bno055/bno055_i2c.c | 57 + drivers/iio/imu/bno055/bno055_ser_core.c | 560 ++++++ 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 + 17 files changed, 2718 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.h
--
2.17.1
PATCH v5 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
@@ -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
@@ -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
PATCH v5 2/14 iio: document linear acceleration modifiers
In reply to Andrea MerelloFrom: 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
@@ -233,6 +233,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: 5.19 +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
PATCH v5 3/14 iio: event_monitor: add linear acceleration modifiers
In reply to Andrea MerelloFrom: 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
@@ -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
PATCH v5 4/14 iio: add modifers for pitch, yaw, roll
In reply to Andrea MerelloFrom: 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
@@ -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
@@ -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
PATCH v5 5/14 iio: document pitch, yaw, roll modifiers
In reply to Andrea MerelloFrom: 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
@@ -2039,3 +2039,12 @@ Description: Available range for the forced calibration value, expressed as: - a range specified as "[min step max]" + +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: 5.19 +Contact: [email protected] +Description: + Raw (unscaled) euler angles readings. Units after + application of scale are deg.
Signature · 1 line
2.17.1
PATCH v5 6/14 iio: event_monitor: add pitch, yaw and roll modifiers
In reply to Andrea MerelloFrom: 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
@@ -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
PATCH v5 7/14 iio: add support for binary attributes
In reply to Andrea MerelloFrom: 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
@@ -1567,7 +1567,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,
@@ -1575,6 +1575,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
PATCH v5 8/14 iio: imu: add Bosch Sensortec BNO055 core driver
In reply to Andrea MerelloFrom: 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 do 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 | 1710 +++++++++++++++++++++++++++++++ drivers/iio/imu/bno055/bno055.h | 12 + 6 files changed, 1731 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
@@ -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
@@ -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
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 + +config BOSCH_BNO055_IIO + tristate
drivers/iio/imu/bno055/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_BOSCH_BNO055_IIO) += bno055.o
drivers/iio/imu/bno055/bno055.c new file +1710 -0
1,710 lines not on this page · raw message
drivers/iio/imu/bno055/bno055.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef __BNO055_H__ +#define __BNO055_H__ + +#include <linux/regmap.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
Re: [v5 08/14] iio: imu: add Bosch Sensortec BNO055 core driver
Quoted 10 lines · Andrea Merello
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 do calculations in order to provide euler
does
Quoted 5 lines
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
sensor?
sensors'?
Quoted 1 line
be customized; this is why AMG mode can still be interesting.
...
drivers/iio/imu/bno055/bno055.c line 27
Quoted 11 lines
drivers/iio/imu/bno055/bno055.c new file +11
-0+#include <linux/bitmap.h> +#include <linux/clk.h> +#include <linux/bitfield.h> +#include <linux/debugfs.h> +#include <linux/device.h> +#include <linux/firmware.h> +#include <linux/gpio/consumer.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/regmap.h> +#include <linux/util_macros.h>
Keep them ordered?
...
drivers/iio/imu/bno055/bno055.c line 33
Quoted 5 lines
drivers/iio/imu/bno055/bno055.c new file +5
-0+#include <linux/iio/iio.h> +#include <linux/iio/triggered_buffer.h> +#include <linux/iio/trigger_consumer.h> +#include <linux/iio/buffer.h> +#include <linux/iio/sysfs.h>
Ditto.
...
drivers/iio/imu/bno055/bno055.c line 39
Quoted 3 lines
drivers/iio/imu/bno055/bno055.c new file +3
-0+#define BNO055_FW_NAME "bno055-caldata" +#define BNO055_FW_EXT ".dat" +#define BNO055_FW_UID_NAME BNO055_FW_NAME "-%*phN" BNO055_FW_EXT
I believe this should be _FMT prefix, since it's not a name (I don't think %*phN is a part of the actual file name).
Quoted 1 line
+#define
BNO055_FW_GENERIC_NAME(BNO055_FW_NAMEBNO055_FW_EXT)
And these macros of macros look unreadable, can we just hardcode format and generic name?
...
drivers/iio/imu/bno055/bno055.c line 129
Quoted 3 lines
drivers/iio/imu/bno055/bno055.c new file +3
-0+#define BNO055_ATTR_VALS (...) \ + .vals = (int[]){ __VA_ARGS__}, \ + .len = ARRAY_SIZE(((int[]){__VA_ARGS__}))
Not sure this adds any readability to the code. Can we simply have an array of int for each case with the explicit ARRAY_SIZE() calls?
...
Quoted 3 lines
+/*
+ * Theoretically the IMU should return data in a given (i.e. fixed) unit
+ * regardless the range setting. This happens for the accelerometer, but not for
regardless of
Quoted 10 lines
+ * the gyroscope; the gyroscope range setting affects the scale.
+ * This is probably due to this[0] bug.
+ * For this reason we map the internal range setting onto the standard IIO scale
+ * attribute for gyro.
+ * Since the bug[0] may be fixed in future, we check for the IMU FW version and
+ * eventually warn the user.
+ * Currently we just don't care about "range" attributes for gyro.
+ *
+ * [0] https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/BNO055-Wrong-sensitivity-resolution-in-datasheet/td-p/10266
+ */
...
drivers/iio/imu/bno055/bno055.c line 222
Quoted 5 lines
drivers/iio/imu/bno055/bno055.c new file +5
-0+/* calibration data may be updated by the IMU */ +if (reg >=BNO055_CALDATA_START && reg <=BNO055_CALDATA_END ) +return true; + +return false;
Can be done in one return statement w/o branch, but probably OK taking into account other related functions.
Quoted 1 line
+}
...
drivers/iio/imu/bno055/bno055.c line 270
Quoted 8 lines
drivers/iio/imu/bno055/bno055.c new file +8
-0+ { + .range_min = 0, + .range_max = 0x7f * 2, + .selector_reg = BNO055_PAGESEL_REG, + .selector_mask = GENMASK(7, 0), + .selector_shift = 0, + .window_start =0 , + .window_len = 0x80
In all cases like this, keep the trailing comma.
Quoted 1 line
+ },
...
Quoted 1 line
+ msleep(20);
Perhaps a comment why so long sleep is needed.
...
drivers/iio/imu/bno055/bno055.c line 327
Quoted 11 lines
drivers/iio/imu/bno055/bno055.c new file +11
-0+static int bno055_system_reset (struct bno055_priv *priv) +{ +int ret; + +if (priv->reset_gpio) { +gpiod_set_value_cansleep (priv->reset_gpio,0 ); +usleep_range (5000 ,10000 ); +gpiod_set_value_cansleep (priv->reset_gpio,1 ); + }else { +if (!priv->sw_reset) +return 0 ;
Can be unified with the above 'else':
} else if (...) {
return 0;
} else {
Quoted 11 lines
drivers/iio/imu/bno055/bno055.c new file +11
-0+ ret =regmap_write (priv->regmap,BNO055_SYS_TRIGGER_REG , +BNO055_SYS_TRIGGER_RST_SYS ); +if (ret) +return ret; + } + +regcache_drop_region (priv->regmap,0x0 ,0xff ); +usleep_range (650000 ,700000 ); + +return 0 ; +}
...
Quoted 1 line
+exit:
exit_unlock: ?
Quoted 3 lines
drivers/iio/imu/bno055/bno055.c new file +3
-0+mutex_unlock (&priv->lock); +return ret; +}
...
drivers/iio/imu/bno055/bno055.c line 437
Quoted 6 lines
drivers/iio/imu/bno055/bno055.c new file +6
-0+ .scan_type = { \ + .sign = 's', \ + .realbits = 16, \ + .storagebits = 16, \ + .endianness =IIO_LE , \ + .repeat = IIO_MOD_##_axis == IIO_MOD_QUATERNION ? 4 : 0 \
+ Comma.
Quoted 1 line
+ }, \
...
drivers/iio/imu/bno055/bno055.c line 536
Quoted 4 lines
drivers/iio/imu/bno055/bno055.c new file +4
-0+ { + .type = IIO_TEMP, + .info_mask_separate =BIT (IIO_CHAN_INFO_PROCESSED ), + .scan_index = -1
+ Comma.
Quoted 1 line
+ },
...
drivers/iio/imu/bno055/bno055.c line 603
Quoted 12 lines
drivers/iio/imu/bno055/bno055.c new file +10
-0+/* +* We always get a request in INT_PLUS_MICRO, but we +* take care of the micro part only when we really have +* non-integer tables. This prevents 32-bit overflow with +* larger integers contained in integer tables. +*/ + req_val = val; +if (attr->type !=IIO_VAL_INT ) { +if (val >2147 ) + val =2147 ;
min() ?
It seems it's not used outside of this branch, so this min() can be integrated into below without corrupting val itself.
Quoted 3 lines
drivers/iio/imu/bno055/bno055.c new file +3
-0+ len /=2 ; + req_val = val *1000000 + val2; + }
...
Quoted 1 line
+ if (first || delta <
best_delta) {
In such cases checking 'first' last might slightly be better.
Quoted 4 lines
drivers/iio/imu/bno055/bno055.c new file +4
-0+ best_delta = delta; + hwval = i; + first = false; + }
...
drivers/iio/imu/bno055/bno055.c line 676
Quoted 2 lines
drivers/iio/imu/bno055/bno055.c new file +2
-0+/* +* IMU reports sensor offests; IIO wants correction
offsets
Quoted 2 lines
(quoted diff) +2
-0+ * offset, thus we need the 'minus' here. + */
...
drivers/iio/imu/bno055/bno055.c line 727
Quoted 5 lines
drivers/iio/imu/bno055/bno055.c new file +4
-0+case IIO_CHAN_INFO_SAMP_FREQ : +if (chan->type !=IIO_MAGN ) +return -EINVAL ; +else
redundant.
Quoted 4 lines
drivers/iio/imu/bno055/bno055.c new file +4
-0+return bno055_get_regmask (priv, val, val2, +BNO055_MAG_CONFIG_REG , +BNO055_MAG_CONFIG_ODR_MASK , + &bno055_mag_odr);
...
drivers/iio/imu/bno055/bno055.c line 1026
Quoted 3 lines
drivers/iio/imu/bno055/bno055.c new file +3
-0+for (i =0 ; i < bno055_acc_range.len; i++) + len +=sysfs_emit_at (buf, len,"%d%c" , bno055_acc_range.vals[i], + (i == bno055_acc_range.len -1 ) ?'\n' :' ' );
You may move the condition out of the loop.
...
Quoted 1 line
+ int ret = 0;
Redundant assignment, see below.
drivers/iio/imu/bno055/bno055.c line 1053
Quoted 6 lines
drivers/iio/imu/bno055/bno055.c new file +6
-0+if (indio_dev->active_scan_mask && + !bitmap_empty (indio_dev->active_scan_mask, _BNO055_SCAN_MAX)) +return -EBUSY ; + +if (sysfs_streq (buf,"0" )) { + ret =bno055_operation_mode_set (priv,BNO055_OPR_MODE_AMG );
return bno055_operation_mode_set(...);
Quoted 1 line
+ } else {
...and drop this with the following decreasing indentation.
Quoted 13 lines
drivers/iio/imu/bno055/bno055.c new file +13
-0+/* +* Coming from AMG means the FMC was off, just switch to fusion +* but don't change anything that doesn't belong to us (i.e let +* FMC stay off. +* Coming from any other fusion mode means we don't need to do +* anything. +*/ +if (priv->operation_mode ==BNO055_OPR_MODE_AMG ) + ret =bno055_operation_mode_set (priv,BNO055_OPR_MODE_FUSION_FMC_OFF ); + } +if (ret) +return ret; +return len;
...
Quoted 1 line
+ if (count <
BNO055_CALDATA_LEN|| pos != 0)
Drop ' != 0' part ?
Quoted 1 line
+ return
-EINVAL;
...
Quoted 1 line
+unlock:
exit_unlock: to be consistent?
Quoted 2 lines
(quoted diff) +2
-0+ mutex_unlock(&priv->lock); + return ret;
...
drivers/iio/imu/bno055/bno055.c line 1462
Quoted 3 lines
drivers/iio/imu/bno055/bno055.c new file +3
-0+/* +* Walk the bitmap and eventually perform several transfers. +* Bitmap ones-fileds that are separated by gaps <= xfer_burst_break_thr
ones-fields ?
Quoted 4 lines
drivers/iio/imu/bno055/bno055.c new file +4
-0+* will be included in same transfer. +* Every time the bitmap contains a gap wider than xfer_burst_break_thr +* then we split the transfer, skipping the gap. +*/
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* + * First transfer will start from the beginnig of the first
beginning
drivers/iio/imu/bno055/bno055.c line 1481
Quoted 12 lines
drivers/iio/imu/bno055/bno055.c new file +11
-0+* ones-field in the bitmap +*/ +if (first) + xfer_start = start; + +/* +* We found the next ones-field; check whether to include it in +* the current transfer or not (i.e. let's perform the current +* transfer and prepare for another one). +*/ +if (!first) {
'else {' ?
Quoted 1 line
+ }
...
drivers/iio/imu/bno055/bno055.c line 1557
Quoted 3 lines
drivers/iio/imu/bno055/bno055.c new file +3
-0+static void bno055_clk_disable (void *arg) +{ +clk_disable_unprepare ((struct clk *)arg);
Redundant casting.
Quoted 1 line
+}
...
drivers/iio/imu/bno055/bno055.c line 1567
Quoted 3 lines
drivers/iio/imu/bno055/bno055.c new file +2
-0+const u8 *caldata_data =NULL ; +int caldata_size =0 ;
No need. See below.
...
drivers/iio/imu/bno055/bno055.c line 1606
Quoted 7 lines
drivers/iio/imu/bno055/bno055.c new file +6
-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)
} else if () {
Quoted 2 lines
drivers/iio/imu/bno055/bno055.c new file +2
-0+dev_warn (dev,"No usable reset method; IMU may be unreliable" ); + }
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* + * Seems that stock FW version conains a bug (see comment at the
the stock
contains
drivers/iio/imu/bno055/bno055.c line 1641
Quoted 2 lines
drivers/iio/imu/bno055/bno055.c new file +2
-0+* beginning of this file) that causes the anglvel scale to be changed +* depending by the chip range setting. We workaround this, but we don't
on the chip
Quoted 1 line
+ * know what other FW version might do..
versions
One period at the end is enough, or add another one if there is a continuation below.
Quoted 1 line
+ */
...
drivers/iio/imu/bno055/bno055.c line 1663
Quoted 6 lines
drivers/iio/imu/bno055/bno055.c new file +5
-0+ ret =request_firmware (&caldata, fw_name_buf, dev); +kfree (fw_name_buf); +if (ret) + ret =request_firmware (&caldata,BNO055_FW_GENERIC_NAME , dev); +
Can be removed to group all related checks together.
Quoted 4 lines
drivers/iio/imu/bno055/bno055.c new file +4
-0+if (ret) +dev_notice (dev,"Calibration file load failed. See instruction in kernel Documentation/iio/bno055.rst" ); + +if (caldata) {
drivers/iio/imu/bno055/bno055.c line 1675
Quoted 10 lines
drivers/iio/imu/bno055/bno055.c new file +8
-0+ caldata_data = caldata->data; + caldata_size = caldata->size; + } + ret =bno055_init (priv, caldata_data, caldata_size); +if (caldata) +release_firmware (caldata); +if (ret) +return ret;
Can be rewritten in a form of
if (caldata) {
ret = bno055_init();
release_firmware(...);
} else {
ret = bno055_init();
}
if (ret)
return ret;
?
...
Quoted 1 line
+#include <
linux/regmap.h>
Missed types.h.
Quoted 4 lines
drivers/iio/imu/bno055/bno055.h new file +4
-0+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;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [v5 08/14] iio: imu: add Bosch Sensortec BNO055 core driver
Il giorno mer 27 apr 2022 alle ore 15:23 Andy Shevchenko <[email protected]> ha scritto:
Quoted 1 line
As usual, some inline comments. OK for the rest.
[...]
Quoted 7 lines
drivers/iio/imu/bno055/bno055.c line 129
Quoted 4 lines
drivers/iio/imu/bno055/bno055.c new file +3
-0+#define BNO055_ATTR_VALS (...) \ + .vals = (int[]){ __VA_ARGS__}, \ + .len = ARRAY_SIZE(((int[]){__VA_ARGS__}))Not sure this adds any readability to the code. Can we simply have an array of int for each case with the explicit
ARRAY_SIZE()calls?
Do you mean moving the vals array out of the structs? Something like:
static int bno055_gyr_scale_vals[] = {125, 1877467, 250, 1877467,
500, 1877467, 1000, 1877467, 2000, 1877467};
static struct bno055_sysfs_attr_aux_data bno055_gyr_scale_aux = {
.fusion_vals = (int[]){1, 900},
.hw_xlate = (int[]){4, 3, 2, 1, 0},
.type = IIO_VAL_FRACTIONAL?
But then I'd make also something like:
#define bno055_sysfs_attr_avail(priv, attr, vals, len) \
_bno055_sysfs_attr_avail(priv, attr##_vals,ARRAY_SIZE(attr##_vals), attr##_aux, vals, len)
And the same for all other users of those structs.
My point is not about readability, but about avoiding as much as possible bugs caused by mismatched attr_vals, attr_aux and ARRAY_SIZE() arg. e.g:bno055_sysfs_attr_avail(priv, bno_foo_vals, ARRAY_SIZE(bno_bar_vals), bno_foobar_aux, vals, len)
I used to make quite a lot of mess until I grouped all the stuff in one struct :/
[...]
Quoted 4 lines
Quoted 2 lines
+ msleep(20);
Perhaps a comment why so long sleep is needed.
DS says that switching mode can last from 7mS up to 19mS depending on the case, but I don't know _why_ it takes so long. I may add a comment that just states that it's a sensor requirement.
[...]
Quoted 6 lines
drivers/iio/imu/bno055/bno055.c line 1026
Quoted 4 lines
drivers/iio/imu/bno055/bno055.c new file +3
-0+for (i =0 ; i < bno055_acc_range.len; i++) + len +=sysfs_emit_at (buf, len,"%d%c" , bno055_acc_range.vals[i], + (i == bno055_acc_range.len -1 ) ?'\n' :' ' );You may move the condition out of the loop.
May you elaborate, please? Do you mean something like: loop one time less, and then call sysfs_emit_at() once more outside the loop, getting rid of the conditional ternary operator at all?
[...]
Quoted 8 lines
drivers/iio/imu/bno055/bno055.c line 1053
Quoted 6 lines
drivers/iio/imu/bno055/bno055.c new file +6
-0+if (indio_dev->active_scan_mask && + !bitmap_empty (indio_dev->active_scan_mask, _BNO055_SCAN_MAX)) +return -EBUSY ; + +if (sysfs_streq (buf,"0" )) { + ret =bno055_operation_mode_set (priv,BNO055_OPR_MODE_AMG );return
bno055_operation_mode_set(...);
Why? bno055_operation_mode_set() returns an error code, while here we need to return the len, or propagate the error code only when it's the case
Quoted 3 lines
Quoted 1 line
+ } else {
...and drop this with the following decreasing indentation.
if you want to drop this, then I can just duplicate if(ret) return ret; i.e. add it after bno055_operation_mode_set(priv, BNO055_OPR_MODE_AMG); and get rid of the else branch (see above)
[...]
Quoted 2 lines
Can be removed to group all related checks together.
I'm not sure what you mean here, but see below
Quoted 26 lines
Quoted 4 lines
drivers/iio/imu/bno055/bno055.c new file +4
-0+if (ret) +dev_notice (dev,"Calibration file load failed. See instruction in kernel Documentation/iio/bno055.rst" ); + +if (caldata) {drivers/iio/imu/bno055/bno055.c line 1675
Quoted 10 lines
drivers/iio/imu/bno055/bno055.c new file +8
-0+ caldata_data = caldata->data; + caldata_size = caldata->size; + } + ret =bno055_init (priv, caldata_data, caldata_size); +if (caldata) +release_firmware (caldata); +if (ret) +return ret;Can be rewritten in a form of
if (caldata) {
ret =bno055_init();
release_firmware(...);
} else {
ret =bno055_init();
}
if (ret)
return ret;
Quoted 1 line
?
Indeed I'd say it could be rewritten as:
if (ret)
ret = request_firmware(&caldata, BNO055_FW_GENERIC_NAME, dev);
if (ret) {
dev_notice(dev, "Calibration file load failed. See
instruction in kernel Documentation/iio/bno055.rst");
ret = bno055_init(priv, NULL, 0);
} else {
ret = bno055_init(priv, caldata->data, caldata->size);
release_firmware(caldata);
}
if (ret)
return ret;Re: [v5 08/14] iio: imu: add Bosch Sensortec BNO055 core driver
Quoted 2 lines · Andrea Merello
Il giorno mer 27 apr 2022 alle ore 15:23 Andy Shevchenko <[email protected]> ha scritto:
...
Quoted 11 lines
Quoted 6 lines
drivers/iio/imu/bno055/bno055.c line 129
Quoted 3 lines
drivers/iio/imu/bno055/bno055.c new file +3
-0+#define BNO055_ATTR_VALS (...) \ + .vals = (int[]){ __VA_ARGS__}, \ + .len = ARRAY_SIZE(((int[]){__VA_ARGS__}))Not sure this adds any readability to the code. Can we simply have an array of int for each case with the explicit
ARRAY_SIZE()calls?Do you mean moving the vals array out of the structs? Something like:
static int bno055_gyr_scale_vals[] = {125, 1877467, 250, 1877467,
500, 1877467, 1000, 1877467, 2000, 1877467};
With the better style, but yes
...[] = {
1, 2, 3, 4, 5
6, 7, 8, 9, 10,
};
Quoted 4 lines
static struct bno055_sysfs_attr_aux_data bno055_gyr_scale_aux = {
.fusion_vals = (int[]){1, 900},
.hw_xlate = (int[]){4, 3, 2, 1, 0},
.type = IIO_VAL_FRACTIONAL(with last comma to be kept, but yes)
Quoted 10 lines
?
But then I'd make also something like:#define bno055_sysfs_attr_avail(priv, attr, vals, len) \ _bno055_sysfs_attr_avail(priv, attr##_vals,
ARRAY_SIZE(attr##_vals), attr##_aux, vals, len)And the same for all other users of those structs.
My point is not about readability,
And my point about readability. The reader, and even the author after some time, may have no clue in this forest of the macros and castings what's going on.
Quoted 8 lines
but about avoiding as much as
possible bugs caused by mismatchedattr_vals,attr_auxandARRAY_SIZE()arg. e.g:bno055_sysfs_attr_avail(priv, bno_foo_vals, ARRAY_SIZE(bno_bar_vals), bno_foobar_aux, vals, len)I used to make quite a lot of mess until I grouped all the stuff in one struct :/
If something you want to prevent at compile time, consider to utilize static_assert() and / or BUILD_BUG_ON() depending on the place in the code (the former is preferred).
...
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+ msleep(20);
Perhaps a comment why so long sleep is needed.
DS says that switching mode can last from 7mS up to 19mS depending on the case, but I don't know _why_ it takes so long. I may add a comment that just states that it's a sensor requirement.
Yes, please add the comment that this time has been chosen to follow data sheet recommendations.
...
Quoted 9 lines
Quoted 5 lines
drivers/iio/imu/bno055/bno055.c line 1026
Quoted 3 lines
drivers/iio/imu/bno055/bno055.c new file +3
-0+for (i =0 ; i < bno055_acc_range.len; i++) + len +=sysfs_emit_at (buf, len,"%d%c" , bno055_acc_range.vals[i], + (i == bno055_acc_range.len -1 ) ?'\n' :' ' );You may move the condition out of the loop.
May you elaborate, please? Do you mean something like: loop one time less, and then call
sysfs_emit_at()once more outside the loop, getting rid of the conditional ternary operator at all?
Regular loop with a space as a delimiter and after it the condition to check i and replace last space by \n. I.o.w. the ternary is an invariant to the loop and no need to call it for each iteration.
...
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
drivers/iio/imu/bno055/bno055.c new file +6
-0+if (indio_dev->active_scan_mask && + !bitmap_empty (indio_dev->active_scan_mask, _BNO055_SCAN_MAX)) +return -EBUSY ; + +if (sysfs_streq (buf,"0" )) { + ret =bno055_operation_mode_set (priv,BNO055_OPR_MODE_AMG );
Quoted 5 lines
Quoted 1 line
return
bno055_operation_mode_set(...);Why?
bno055_operation_mode_set()returns an error code, while here we need to return the len, or propagate the error code only when it's the case
Ah good point.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+ } else {
...and drop this with the following decreasing indentation.
if you want to drop this, then I can just duplicate if(ret) return ret; i.e. add it after
bno055_operation_mode_set(priv, BNO055_OPR_MODE_AMG); and get rid of the else branch (see above)
Yes, but now, reading the original code again, I'm wondering why you are not using kstrtobool().
...
Quoted 32 lines
Quoted 1 line
Can be removed to group all related checks together.
I'm not sure what you mean here, but see below
Quoted 26 lines
Quoted 4 lines
drivers/iio/imu/bno055/bno055.c new file +4
-0+if (ret) +dev_notice (dev,"Calibration file load failed. See instruction in kernel Documentation/iio/bno055.rst" ); + +if (caldata) {drivers/iio/imu/bno055/bno055.c line 1675
Quoted 10 lines
drivers/iio/imu/bno055/bno055.c new file +8
-0+ caldata_data = caldata->data; + caldata_size = caldata->size; + } + ret =bno055_init (priv, caldata_data, caldata_size); +if (caldata) +release_firmware (caldata); +if (ret) +return ret;Can be rewritten in a form of
if (caldata) {
ret =bno055_init();
release_firmware(...);
} else {
ret =bno055_init();
}
if (ret)
return ret;Quoted 1 line
?
Quoted 7 lines
Indeed I'd say it could be rewritten as:
if (ret) ret = request_firmware(&caldata, BNO055_FW_GENERIC_NAME, dev); if (ret) { dev_notice(dev, "Calibration file load failed. Seeinstruction in kernel
Documentation/iio/bno055.rst");
Missed \n.
Quoted 7 lines
ret = bno055_init(priv, NULL, 0);
} else {
ret = bno055_init(priv, caldata->data, caldata->size);
release_firmware(caldata);
}
if (ret)
return ret;Yes, something like this. Experiment with it and choose which one is read better.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [v5 08/14] iio: imu: add Bosch Sensortec BNO055 core driver
Il giorno lun 2 mag 2022 alle ore 12:12 Andy Shevchenko <[email protected]> ha scritto:
One inline comment. OK for the rest
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/iio/imu/bno055/bno055.c new file +3
-0+#define BNO055_ATTR_VALS (...) \ + .vals = (int[]){ __VA_ARGS__}, \ + .len = ARRAY_SIZE(((int[]){__VA_ARGS__}))
[...]
Quoted 3 lines
And my point about readability. The reader, and even the author after some time, may have no clue in this forest of the macros and castings what's going on.
While I'm OK wrt your point in general, consider that it's just a three LOC macro, used only in a few structs just below. I wouldn't say it's so inricated; I've seen by far worse in the kernel :)
Quoted 6 lines
Quoted 6 lines
but about avoiding as much as
possible bugs caused by mismatchedattr_vals,attr_auxandARRAY_SIZE()arg. e.g:bno055_sysfs_attr_avail(priv, bno_foo_vals, ARRAY_SIZE(bno_bar_vals), bno_foobar_aux, vals, len)
Quoted 6 lines
Quoted 2 lines
I used to make quite a lot of mess until I grouped all the stuff in one struct :/
If something you want to prevent at compile time, consider to utilize
static_assert()and / orBUILD_BUG_ON()depending on the place in the code (the former is preferred).
I would be happy to get rid of my macro and use those assertion things, but I can't see how exactly. Do you have any advice about how to take advantage of them for catching bugs like the one above in this specific case?
PATCH v5 9/14 iio: document bno055 private sysfs attributes
In reply to Andrea MerelloFrom: 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
@@ -0,0 +1,81 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_accel_raw_range +KernelVersion: 5.19 +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: 5.19 +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: 5.19 +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: 5.19 +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: 5.19 +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: 5.19 +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: 5.19 +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: 5.19 +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: 5.19 +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: 5.19 +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: 5.19 +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
PATCH v5 10/14 iio: document "serialnumber" sysfs attribute
In reply to Andrea MerelloFrom: 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
@@ -2048,3 +2048,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: 5.19 +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
PATCH v5 11/14 dt-bindings: iio/imu: Add Bosch BNO055
In reply to Andrea MerelloFrom: 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
@@ -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
PATCH v5 12/14 iio: imu: add BNO055 serdev driver
In reply to Andrea MerelloFrom: 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.h | 104 ++++ 4 files changed, 679 insertions(+) create mode 100644 drivers/iio/imu/bno055/bno055_ser_core.c create mode 100644 drivers/iio/imu/bno055/bno055_ser_trace.h
drivers/iio/imu/bno055/Kconfig +10 -0
@@ -2,3 +2,13 @@ config BOSCH_BNO055_IIO tristate + +config BOSCH_BNO055_SERIAL + tristate "Bosch BNO055 attached via UART" + depends on SERIAL_DEV_BUS + select BOSCH_BNO055_IIO + 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
@@ -1,3 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_BOSCH_BNO055_IIO) += 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.h new file +104 -0
104 lines not on this page · raw message
Signature · 1 line
2.17.1
kernel test robot
build botRe: [v5 12/14] iio: imu: add BNO055 serdev driver
Thank you for the patch! Yet something to improve:
Hi Andrea,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on linus/master linux/master v5.18-rc4 next-20220426] [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]
url: https://github.com/intel-lab-lkp/linux/commits/Andrea-Merello/Add-support-for-Bosch-BNO055-IMU/20220426-212132 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20220427/[email protected]/config) compiler: arceb-elf-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/675ca9cd13af45cc5943dd15caad5e866fd7c971
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Andrea-Merello/Add-support-for-Bosch-BNO055-IMU/20220426-212132 git checkout 675ca9cd13af45cc5943dd15caad5e866fd7c971
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> make[5]: *** No rule to make target 'drivers/iio/imu/bno055/bno055_ser_trace.o', needed by 'drivers/iio/imu/bno055/built-in.a'.
make[5]: Target '__build' not remade because of errors.
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
Re: [v5 12/14] iio: imu: add BNO055 serdev driver
Quoted 26 lines · kernel test robot
Hi Andrea,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on linus/master linux/master v5.18-rc4 next-20220426] [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]url: https://github.com/intel-lab-lkp/linux/commits/Andrea-Merello/Add-support-for-Bosch-BNO055-IMU/20220426-212132 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20220427/202204271554.EiuIRNPI-lkp(a)intel.com/config) compiler: arceb-elf-gcc (GCC) 11.3.0reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/675ca9cd13af45cc5943dd15caad5e866fd7c971
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Andrea-Merello/Add-support-for-Bosch-BNO055-IMU/20220426-212132 git checkout675ca9cd13af45cc5943dd15caad5e866fd7c971
# save the config file
mkdirbuild_dir&& cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash
Quoted 7 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All errors (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
make[5]: *** No rule to make target '
drivers/iio/imu/bno055/bno055_ser_trace.o', needed by 'drivers/iio/imu/bno055/built-in.a'.make[5]: Target '
__build' not remade because of errors.
You need to add a C-file with the only line
#include <..._trace.h>
And drop that include from the ..._core.c.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [v5 12/14] iio: imu: add BNO055 serdev driver
Il giorno mer 27 apr 2022 alle ore 15:41 Andy Shevchenko <[email protected]> ha scritto:
Quoted 33 lines · kernel test robot
Quoted 31 lines
Hi Andrea,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on linus/master linux/master v5.18-rc4 next-20220426] [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]url: https://github.com/intel-lab-lkp/linux/commits/Andrea-Merello/Add-support-for-Bosch-BNO055-IMU/20220426-212132 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20220427/202204271554.EiuIRNPI-lkp(a)intel.com/config) compiler: arceb-elf-gcc (GCC) 11.3.0reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/675ca9cd13af45cc5943dd15caad5e866fd7c971
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Andrea-Merello/Add-support-for-Bosch-BNO055-IMU/20220426-212132 git checkout675ca9cd13af45cc5943dd15caad5e866fd7c971
# save the config file
mkdirbuild_dir&& cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bashIf you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All errors (new ones prefixed by >>):
Quoted 8 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line
make[5]: *** No rule to make target '
drivers/iio/imu/bno055/bno055_ser_trace.o', needed by 'drivers/iio/imu/bno055/built-in.a'.make[5]: Target '
__build' not remade because of errors.You need to add a C-file with the only line
#include <
..._trace.h>And drop that include from the
_core.c.
Hum, I'm a bit confused here: the bno055_ser_core.c file explicitly looks for that tracepoints (e.g. it calls trace_send_chunks() and friends); dropping the include prevents build here because there would be no definition for those tracepoints.
There is already a C file bno055_ser_trace.c that just contains the said include and it defines CREATE_TRACE_POINTS; I see other drivers like dwc3 do the same..
But my problem is that I cannot reproduce the issue found by the bot:
the compiler that is downloaded by the script doesn't run on my build box because it wants a newer libc (I was hoping that those compilers were statically linked, but they aren't), while any other attempt I did with other older compilers resulted in either successful build or failed with other weird, apparently unrelated, errors about relocation issues (of course I tried with the arch and config used by the build bot).
Is there any build farm publicly available or something like that?
Quoted 3 lines
--
With Best Regards,
Andy Shevchenko
Re: [v5 12/14] iio: imu: add BNO055 serdev driver
Il giorno mar 3 mag 2022 alle ore 09:48 Andrea Merello <[email protected]> ha scritto:
[...]
Quoted 6 lines
Quoted 5 lines
You need to add a C-file with the only line
#include <
..._trace.h>And drop that include from the
_core.c.
Quoted 8 lines
Hum, I'm a bit confused here: the
bno055_ser_core.cfile explicitly looks for that tracepoints (e.g. it callstrace_send_chunks()and friends); dropping the include prevents build here because there would be no definition for those tracepoints.There is already a C file
bno055_ser_trace.cthat just contains the said include and it definesCREATE_TRACE_POINTS; I see other drivers like dwc3 do the same..
Oops.. it turned out that I just had this almost-empty C file as untracked in my git tree, and it ended up not being included in patches also. Being it laying in my src tree caused the build to succeed.
I have been misled by the other problem I (still) have (below); I was focused on the wrong thing, sorry.
Quoted 14 lines
But my problem is that I cannot reproduce the issue found by the bot:
the compiler that is downloaded by the script doesn't run on my build box because it wants a newer libc (I was hoping that those compilers were statically linked, but they aren't), while any other attempt I did with other older compilers resulted in either successful build or failed with other weird, apparently unrelated, errors about relocation issues (of course I tried with the arch and config used by the build bot).Is there any build farm publicly available or something like that?
Quoted 3 lines
--
With Best Regards,
Andy Shevchenko
Re: [v5 12/14] iio: imu: add BNO055 serdev driver
Quoted 21 lines · Andrea Merello
Il giorno mar 3 mag 2022 alle ore 09:48 Andrea Merello <[email protected]> ha scritto:
[...]
Quoted 6 lines
Quoted 5 lines
You need to add a C-file with the only line
#include <
..._trace.h>And drop that include from the
_core.c.Quoted 8 lines
Hum, I'm a bit confused here: the
bno055_ser_core.cfile explicitly looks for that tracepoints (e.g. it callstrace_send_chunks()and friends); dropping the include prevents build here because there would be no definition for those tracepoints.There is already a C file
bno055_ser_trace.cthat just contains the said include and it definesCREATE_TRACE_POINTS; I see other drivers like dwc3 do the same..
Quoted 7 lines
Oops.. it turned out that I just had this almost-empty C file as untracked in my git tree, and it ended up not being included in patches also. Being it laying in my src tree caused the build to succeed.
I have been misled by the other problem I (still) have (below); I was focused on the wrong thing, sorry.
So, there are two reports:
1) missed C file;
2) possible missed prototype.
To solve 1) you need to add the C file to the patch. To solve 2) you need either declare it static or put it into the header file (I haven't checked deeply which one is your case).
Quoted 8 lines
Quoted 8 lines
But my problem is that I cannot reproduce the issue found by the bot:
the compiler that is downloaded by the script doesn't run on my build box because it wants a newer libc (I was hoping that those compilers were statically linked, but they aren't), while any other attempt I did with other older compilers resulted in either successful build or failed with other weird, apparently unrelated, errors about relocation issues (of course I tried with the arch and config used by the build bot).
You may use compilers from kernel.org that don't require any libc at all (only good for kernel compilation).
Quoted 1 line
Quoted 1 line
Is there any build farm publicly available or something like that?
Not of my knowledge.
Signature · 2 lines
With Best Regards, Andy Shevchenko
kernel test robot
build botRe: [v5 12/14] iio: imu: add BNO055 serdev driver
In reply to Andrea MerelloThank you for the patch! Perhaps something to improve:
Hi Andrea,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master linux/master v5.18-rc4 next-20220427] [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]
url: https://github.com/intel-lab-lkp/linux/commits/Andrea-Merello/Add-support-for-Bosch-BNO055-IMU/20220426-212132 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg config: alpha-randconfig-r036-20220427 (https://download.01.org/0day-ci/archive/20220427/[email protected]/config) compiler: alpha-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/675ca9cd13af45cc5943dd15caad5e866fd7c971
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Andrea-Merello/Add-support-for-Bosch-BNO055-IMU/20220426-212132
git checkout 675ca9cd13af45cc5943dd15caad5e866fd7c971
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=alpha SHELL=/bin/bash drivers/iio/imu/bno055/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/iio/imu/bno055/bno055.c:1317:5: warning: no previous prototype for 'bno055_debugfs_reg_access' [-Wmissing-prototypes]
1317 | int bno055_debugfs_reg_access(struct iio_dev *iio_dev, unsigned int reg,
| ^~~~~~~~~~~~~~~~~~~~~~~~~
vim +/bno055_debugfs_reg_access +1317 drivers/iio/imu/bno055/bno055.c
2f40e22369ed70 Andrea Merello 2022-04-26 1316
2f40e22369ed70 Andrea Merello 2022-04-26 @1317 int bno055_debugfs_reg_access(struct iio_dev *iio_dev, unsigned int reg,
2f40e22369ed70 Andrea Merello 2022-04-26 1318 unsigned int writeval, unsigned int *readval)
2f40e22369ed70 Andrea Merello 2022-04-26 1319 {
2f40e22369ed70 Andrea Merello 2022-04-26 1320 return 0;
2f40e22369ed70 Andrea Merello 2022-04-26 1321 }
2f40e22369ed70 Andrea Merello 2022-04-26 1322 #endif2f40e22369ed70 Andrea Merello 2022-04-26 1323
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
PATCH v5 13/14 iio: imu: add BNO055 I2C driver
In reply to Andrea MerelloFrom: 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
@@ -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_IIO + 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
@@ -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
PATCH v5 14/14 docs: iio: add documentation for BNO055 driver
In reply to Andrea MerelloFrom: 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).
--- Documentation/iio/bno055.rst | 50 ++++++++++++++++++++++++++++++++++++ Documentation/iio/index.rst | 2 ++ 2 files changed, 52 insertions(+) create mode 100644 Documentation/iio/bno055.rst
Documentation/iio/bno055.rst new file +50 -0
@@ -0,0 +1,50 @@ +.. 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
@@ -10,3 +10,5 @@ Industrial I/O iio_configfs ep93xx_adc + + bno055
Signature · 1 line
2.17.1
Quoted 16 lines · Andrea Merello
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 tool7/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
Quoted 6 lines
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
FWIW,
for non-commented patches (12 out of 14 AFAICS).
Quoted 144 lines
Differences wrt v4:
- be more tolerant wrt unrecognized chip IDs
- rename 'serial_number' attribute in 'serialnumber'
- fix missing NULL variable initialization
- usesign_extend32()instead of s16 casting where appropriate
- fix quaternion unit
- minor stuff (e.g. comments..)
- reduce (slightly) locking in serdev driver
- rework tracepoint support (e.g. remove dedicated config option)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
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 driverDocumentation/ABI/testing/sysfs-bus-iio | 25 + .../ABI/testing/sysfs-bus-iio-bno055 | 81 + .../bindings/iio/imu/bosch,bno055.yaml | 59 + Documentation/iio/bno055.rst | 50 + 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 | 1710 +++++++++++++++++ drivers/iio/imu/bno055/bno055.h | 12 + drivers/iio/imu/bno055/bno055_i2c.c | 57 + drivers/iio/imu/bno055/bno055_ser_core.c | 560 ++++++ 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 + 17 files changed, 2718 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.h--
2.17.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 19 lines · On Wed, 27 Apr 2022 15:42:49 +0200 Andy Shevchenko <[email protected]>…
Quoted 18 lines · Andrea Merello
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 tool7/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 bindings12/14: adds serdev BNO055 driver to actually use the IMU via serial line
Quoted 9 lines
Quoted 4 lines
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 calibrationFWIW,
Reviewed-by Andy Shevchenko <[email protected]>for non-commented patches (12 out of 14 AFAICS).
FWIW I'm fine with the series once you've tidied up the stuff Andy picked up on.
Thanks Andy for the detailed reviewing btw.
Jonathan
Quoted 147 lines
Quoted 144 lines
Differences wrt v4:
- be more tolerant wrt unrecognized chip IDs
- rename 'serial_number' attribute in 'serialnumber'
- fix missing NULL variable initialization
- usesign_extend32()instead of s16 casting where appropriate
- fix quaternion unit
- minor stuff (e.g. comments..)
- reduce (slightly) locking in serdev driver
- rework tracepoint support (e.g. remove dedicated config option)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
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 driverDocumentation/ABI/testing/sysfs-bus-iio | 25 + .../ABI/testing/sysfs-bus-iio-bno055 | 81 + .../bindings/iio/imu/bosch,bno055.yaml | 59 + Documentation/iio/bno055.rst | 50 + 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 | 1710 +++++++++++++++++ drivers/iio/imu/bno055/bno055.h | 12 + drivers/iio/imu/bno055/bno055_i2c.c | 57 + drivers/iio/imu/bno055/bno055_ser_core.c | 560 ++++++ 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 + 17 files changed, 2718 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.h--
2.17.1
Il giorno dom 1 mag 2022 alle ore 18:54 Jonathan Cameron <[email protected]> ha scritto:
Quoted 32 lines
Quoted 19 lines · On Wed, 27 Apr 2022 15:42:49 +0200 Andy Shevchenko <[email protected]>…
Quoted 18 lines · Andrea Merello
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 tool7/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 bindings12/14: adds serdev BNO055 driver to actually use the IMU via serial line
Quoted 9 lines
Quoted 4 lines
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 calibrationFWIW,
Reviewed-by Andy Shevchenko <[email protected]>for non-commented patches (12 out of 14 AFAICS).
Quoted 6 lines
FWIW I'm fine with the series once you've tidied up the stuff Andy picked up on.
Thanks Andy for the detailed reviewing btw.
Jonathan
I'm very grateful to both of you and to everyone who commented on those patches. Thanks :). Beside the "Reviewed-by" tags where appropriate, is it usual/appropriate to put some tag like "Thanks-to .. [for comments]" ?
BTW I have also gone through some kernel-robot reports; they also state "If you fix the issue, kindly add following tag as appropriate
be OK to add this tag to a patch that just fixes what is reported, but I'm unsure whether it is appropriate to add this tag to the patches in my series, because they add the code and the fix at once. Any advice here?
Andrea
Quoted 5 lines · Andrea Merello
Il giorno dom 1 mag 2022 alle ore 18:54 Jonathan Cameron <[email protected]> ha scritto:
Quoted 3 lines
Quoted 1 line · On Wed, 27 Apr 2022 15:42:49 +0200 Andy Shevchenko <[email protected]>…
On Tue, Apr 26, 2022 at 3:11 PM Andrea Merello <[email protected]> wrote:
...
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
FWIW,
Reviewed-by Andy Shevchenko <[email protected]>for non-commented patches (12 out of 14 AFAICS).
FWIW I'm fine with the series once you've tidied up the stuff Andy picked up on.
Thanks Andy for the detailed reviewing btw.
You/re welcome!
Quoted 4 lines
I'm very grateful to both of you and to everyone who commented on those patches. Thanks :). Beside the "Reviewed-by" tags where appropriate, is it usual/appropriate to put some tag like "Thanks-to .. [for comments]" ?
Nope, just mention that in the cover letter.
Quoted 7 lines
BTW I have also gone through some kernel-robot reports; they also state "If you fix the issue, kindly add following tag as appropriate
be OK to add this tag to a patch that just fixes what is reported, but I'm unsure whether it is appropriate to add this tag to the patches in my series, because they add the code and the fix at once. Any advice here?
For this we specifically amended the kernel documentation recently.
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#using-reported-by-tested-by-reviewed-by-suggested-by-and-fixes
"The tag is intended for bugs; please do not use it to credit feature requests."
Signature · 2 lines
With Best Regards, Andy Shevchenko
Il giorno lun 2 mag 2022 alle ore 09:48 Andy Shevchenko <[email protected]> ha scritto:
Quoted 1 line
[ .. ]
Quoted 8 lines
Quoted 7 lines
BTW I have also gone through some kernel-robot reports; they also state "If you fix the issue, kindly add following tag as appropriate
be OK to add this tag to a patch that just fixes what is reported, but I'm unsure whether it is appropriate to add this tag to the patches in my series, because they add the code and the fix at once. Any advice here?
Quoted 4 lines
For this we specifically amended the kernel documentation recently.
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#using-reported-by-tested-by-reviewed-by-suggested-by-and-fixes"The tag is intended for bugs; please do not use it to credit feature requests."
Well, no any feature request to credit here; a bug and its fix are involved. Sounds more like a "yes" so far.. But it wouldn't be clear what the robot did report indeed (squashed bugs and fixes).. Maybe a "thank" in the cover letter also to it would suffice?
Quoted 3 lines
--
With Best Regards,
Andy Shevchenko
Quoted 2 lines · Andrea Merello
Il giorno lun 2 mag 2022 alle ore 09:48 Andy Shevchenko <[email protected]> ha scritto:
...
Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
BTW I have also gone through some kernel-robot reports; they also state "If you fix the issue, kindly add following tag as appropriate
be OK to add this tag to a patch that just fixes what is reported, but I'm unsure whether it is appropriate to add this tag to the patches in my series, because they add the code and the fix at once. Any advice here?
For this we specifically amended the kernel documentation recently.
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#using-reported-by-tested-by-reviewed-by-suggested-by-and-fixes
Quoted 6 lines
Quoted 1 line
"The tag is intended for bugs; please do not use it to credit feature requests."
Well, no any feature request to credit here; a bug and its fix are involved. Sounds more like a "yes" so far.. But it wouldn't be clear what the robot did report indeed (squashed bugs and fixes).. Maybe a "thank" in the cover letter also to it would suffice?
The reported from bots should be used when your patches.changes induced by those reports, it seems otherwise in your case.,
Signature · 2 lines
With Best Regards, Andy Shevchenko