Re: [PATCH v6 7/7] iio: imu: st_lsm6dsx: Add support for rotation sensor
From: Andy Shevchenko
Date: Wed Feb 25 2026 - 06:50:52 EST
On Wed, Feb 25, 2026 at 11:18:13AM +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_sf_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.
...
> +int st_lsm6dsx_sf_probe(struct st_lsm6dsx_hw *hw, const char *name)
> +{
> + const struct st_lsm6dsx_sf_settings *settings;
> + struct st_lsm6dsx_sensor *sensor;
> + struct iio_dev *iio_dev;
Maybe
int ret; // choose better name if any
> + iio_dev = devm_iio_device_alloc(hw->dev, sizeof(*sensor));
> + if (!iio_dev)
> + return -ENOMEM;
> +
> + settings = &hw->settings->sf_settings;
> + sensor = iio_priv(iio_dev);
> + sensor->id = ST_LSM6DSX_ID_SF;
> + sensor->hw = hw;
> + sensor->hwfifo_odr_mHz = settings->odr_table.odr_avl[0].milli_hz;
> + sensor->watermark = 1;
> + iio_dev->modes = INDIO_DIRECT_MODE;
> + iio_dev->info = &st_lsm6dsx_sf_info;
> + iio_dev->channels = settings->chan;
> + iio_dev->num_channels = settings->chan_len;
> + if (snprintf(sensor->name, sizeof(sensor->name), "%s_sf", name) >=
> + sizeof(sensor->name))
> + return -E2BIG;
ret = snprintf(sensor->name, sizeof(sensor->name), "%s_sf", name);
if (ret >= sizeof(sensor->name))
return -E2BIG;
I find this easier to read and follow.
> + iio_dev->name = sensor->name;
> +
> + /*
> + * Put the IIO device pointer in the iio_devs array so that the caller
> + * can set up a buffer and register this IIO device.
> + */
> + hw->iio_devs[ST_LSM6DSX_ID_SF] = iio_dev;
> +
> + return 0;
> +}
--
With Best Regards,
Andy Shevchenko