From: Francesco Lavra <flavra@baylibre.com>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: "Lorenzo Bianconi" <lorenzo@kernel.org>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 3/3] iio: imu: st_lsm6dsx: add support for rotation sensor
Date: Tue, 20 Jan 2026 10:28:15 +0100 [thread overview]
Message-ID: <851180c6f41f8c9cc79d6412eb97f381f0312f00.camel@baylibre.com> (raw)
In-Reply-To: <aW4Ic5bUId3MG4em@smile.fi.intel.com>
[-- Attachment #1: Type: text/plain, Size: 4732 bytes --]
On Mon, 2026-01-19 at 12:33 +0200, Andy Shevchenko wrote:
> On Mon, Jan 19, 2026 at 11:04:49AM +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.
>
> ...
>
> > st_lsm6dsx_push_tagged_data(struct st_lsm6dsx_hw *hw, u8 tag,
>
> > case ST_LSM6DSX_EXT2_TAG:
> > iio_dev = hw->iio_devs[ST_LSM6DSX_ID_EXT2];
> > break;
> > + case ST_LSM6DSX_ROT_TAG:
> > + /*
> > + * The sensor reports only the {X, Y, Z} elements of
> > the
> > + * quaternion vector; set the W value to 0 (it can be
> > derived
> > + * from the {X, Y, Z} values due to the property that
> > the vector
> > + * is normalized).
> > + */
> > + *(u16 *)(data + ST_LSM6DSX_SAMPLE_SIZE) = 0;
>
> This looks confusing taking into account
>
> s16 val = le16_to_cpu(*(__le16 *)data);
>
> (which actually should use le16_to_cpup() instead of the direct
> conversion).
The above val variable is used to do a (val >= ST_LSM6DSX_INVALID_SAMPLE)
check, which actually should be done only if (tag == ST_LSM6DSX_ACC_TAG ||
tag == ST_LSM6DSX_GYRO_TAG).
I will add a patch to fix this (it will fix commit 960506ed2c69 "iio: imu:
st_lsm6dsx: enable drdy-mask if available")
> > + iio_dev = hw->iio_devs[ST_LSM6DSX_ID_SF];
> > + break;
> > default:
> > return -EINVAL;
> > }
>
> ...
>
> > +int st_lsm6dsx_sf_set_enable(struct st_lsm6dsx_sensor *sensor, bool
> > enable)
> > +{
> > + struct st_lsm6dsx_hw *hw = sensor->hw;
> > + const struct st_lsm6dsx_reg *en_reg;
> > + int err;
> > +
> > + guard(mutex)(&hw->page_lock);
> > +
> > + en_reg = &hw->settings->sf_settings.enable;
> > + err = st_lsm6dsx_sf_set_page(hw, true);
> > + if (err < 0)
>
> Do you need ' < 0' here? Why isn't it required at the end of the
> function?
Will drop ' < 0'
> > + return err;
> > +
> > + err = regmap_assign_bits(hw->regmap, en_reg->addr, en_reg-
> > >mask, enable);
> > + if (err < 0) {
>
> is not needed.
>
> > + st_lsm6dsx_sf_set_page(hw, false);
> > + return err;
> > + }
> > +
> > + return st_lsm6dsx_sf_set_page(hw, false);
> > +}
>
> And IIRC I replied that these _sf_set_page() seems to be used only with
> the explicit boolean value, which means a good hint that it needs to be
> split just to two functions doing for true and false. It will increase
> the readability of the code in both places (in the caller and callee).
OK
> ...
>
> > + snprintf(sensor->name, sizeof(sensor->name), "%s_sf", name);
>
> Does GCC complain on this (`make W=1` build)?
> Since this can cut the string and we don't check the return value, the Q
> is:
> is this okay to have a reduced string?
gcc does not complain with W=1. sensor->name is appropriately sized to
accommodate the longest possible name; if it wasn't, the string would be
cut in the accel and gyro IIO devices too (which use a longer suffix than
"_sf").
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
next prev parent reply other threads:[~2026-01-20 9:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-19 10:04 [PATCH v3 0/3] imu: st_lsm6dsx: Add " Francesco Lavra
2026-01-19 10:04 ` [PATCH v3 1/3] iio: imu: st_lsm6dsx: set FIFO ODR for accelerometer and gyroscope only Francesco Lavra
2026-01-19 10:04 ` [PATCH v3 2/3] iio: imu: st_lsm6dsx: set buffer sampling frequency for accelerometer only Francesco Lavra
2026-01-19 10:04 ` [PATCH v3 3/3] iio: imu: st_lsm6dsx: add support for rotation sensor Francesco Lavra
2026-01-19 10:33 ` Andy Shevchenko
2026-01-20 9:28 ` Francesco Lavra [this message]
2026-01-20 9:36 ` Andy Shevchenko
2026-01-20 10:03 ` Francesco Lavra
2026-01-20 10:25 ` Andy Shevchenko
2026-01-20 12:23 ` Francesco Lavra
2026-01-20 12:29 ` Andy Shevchenko
2026-01-20 6:46 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=851180c6f41f8c9cc79d6412eb97f381f0312f00.camel@baylibre.com \
--to=flavra@baylibre.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®