Re: [PATCH v7 6/6] iio: imu: st_lsm6dsx: Add support for rotation sensor

From: Andy Shevchenko

Date: Wed Mar 04 2026 - 08:39:24 EST


On Wed, Mar 04, 2026 at 09:07:11AM +0100, Francesco Lavra wrote:
> Some IMU chips in the LSM6DSX family have sensor fusion features that
> combine data from the accelerometer and gyroscope. One of these features
> generates rotation vector data and makes it available in the hardware
> FIFO as a quaternion (more specifically, the X, Y and Z components of the
> quaternion vector, expressed as 16-bit half-precision floating-point
> numbers).
>
> Add support for a new sensor instance that allows receiving sensor fusion
> data, by defining a new struct st_lsm6dsx_fusion_settings (which contains
> chip-specific details for the sensor fusion functionality), and adding this
> struct as a new field in struct st_lsm6dsx_settings. In st_lsm6dsx_core.c,
> populate this new struct for the LSM6DSV and LSM6DSV16X chips, and add the
> logic to initialize an additional IIO device if this struct is populated
> for the hardware type being probed.
> Note: a new IIO device is being defined (as opposed to adding channels to
> an existing device) because the rate at which sensor fusion data is
> generated may not match the data rate from any of the existing devices.
>
> Tested on LSMDSV16X.

...

> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c

+ cleanup.h
+ errno.h

> +#include <linux/iio/iio.h>
> +#include <linux/iio/sysfs.h>
> +#include <linux/mutex.h>
> +#include <linux/regmap.h>
> +#include <linux/sprintf.h>
> +#include <linux/types.h>
> +#include <linux/units.h>

...

> + case IIO_CHAN_INFO_SAMP_FREQ: {
> + u32 odr_mHz = val * MILLI + val2 * (MILLI / MICRO);
> + u8 odr_val;
> +
> + /* check that the requested frequency is supported */
> + err = st_lsm6dsx_fusion_get_odr_val(settings, odr_mHz,
> + &odr_val);

In cases like this I would leave it on a single line. Here I counted only 81
characters.

> + if (err)
> + return err;
> +
> + sensor->hwfifo_odr_mHz = odr_mHz;
> + return 0;
> + }

--
With Best Regards,
Andy Shevchenko