imu: st_lsm6dsx: Add support for rotation sensor
Subsystems (3)
v9 cover imu: st_lsm6dsx: Add support for rotation sensor
This series adds support for the rotation sensor functionality present in some chips from the ST LSM6DSX IMU family.
The IIO ABI has been amended to allow the use of floating-point data and a "quaternion axis" channel modifier in IIO buffers.
The use of the new modifier depends on [0] to get the correct sizing of the buffer in userspace.
Tested on LSM6DSV16X.
Changes from v8 [8]:
- changed comments for IIO_SCAN_FORMAT_* macros to use proper kernel doc format with one comment per macro (David)
- in tools/iio, added error print if 1-byte floats are encountered and if 2-byte floats are encountered when unsupported (David)
- in tools/iio, renamed signchar variable to formatchar (David)
- added David's Reviewed-by tag to patch 5
- in st_lsm6dsx_fusion.c, avoided mixing cleanup and gotos by adding a helper function (Jonathan)
- in st_lsm6dsx_fusion.c, removed leading double spaces in comment (Jonathan)
- in ST_LSM6DSX_CHANNEL_ROT macro, replaced literal 'f' with IIO_SCAN_FORMAT_FLOAT
Changes from v7 [7]:
- added Lorenzo's Acked-by tag to patch 1
- in st_lsm6dsx_buffer.c, added st_lsm6dsx_check_data() helper function (Lorenzo)
- added definition of IIO_SCAN_FORMAT_* symbolic constants to restrict flexibility of what can go in .format (Jonathan)
- re-added @sign description in kernel.doc comment for
struct iio_scan_type, mentioning that @format should be used in new code (Jonathan)
- in tools/iio/iio_generic_buffer, replaced legacy __fp16 type with standard-compliant _Float16 (David)
- in tools/iio/iio_generic_buffer, added check for compiler support (David), so that compilation does not fail with compilers that don't support _Float16: tested with gcc for x86-64 (supported), for aarch64 (supported), for riscv-64 (not supported), clang for x86-64 (not supported)
- in tols/iio/iio_utils.h, replaced unsigned with char type for format field in struct iio_channel_info (David)
- renamed "partial quaternion" modifier to "quaternion axis"
- moved new modifier value at the end of enum iio_modifier (David)
- squashed the two words together in the modifier name (Jonathan)
- in ABI doc for new modifier, fixed typo and angle units (David)
- in ABI doc for new modifier, fixed kernel-doc warning (kernel test robot)
- in st_lsm6dsx_fusion.c, added missing header includes (Andy)
Changes from v6 [6]:
- dropped patches 1 and 2 (already picked up by Jonathan)
- added floating-point support to iio-tools (Andy)
- replaced sign field in struct iio_scan_type with union instead of format field (David, Jonathan)
- changed [s|u|f] to [f|s|u] in ABI and driver documentation files (Andy)
- removed IIO_CUSTOM channel type in favor of IIO_MOD_PARTIAL_QUATERNION modifier (David, Andy)
- replaced "sf" with "fusion" in type, variable and function names (David)
- added copyright statement in st_lsm6dsx_fusion.c (David)
- added ret variable in st_lsm6dsx_fusion_probe() for better readability (Andy)
- modified data structure holding the list of available frequencies in order to replace device attribute with .read_avail callback (David)
Changes from v5 [5]:
- cleaned up FIFO data representation in st_lsm6dsx_read_tagged_fifo() to avoid casting (Andy, Jonathan)
- renamed 'sign' field to format in struct iio_scan_type
- added support for IEEE 754 floating-point format in buffer scan elements
- added custom data type in the ABI (IIO_CUSTOM in enum iio_chan_type) (Jonathan)
- added driver document in Documentation/iio/ (Jonathan)
Changes from v4 [4]:
- changed data parameter in st_lsm6dsx_push_tagged_data() to __le16 * (Andy)
Changes from v3 [3]:
- added patch 3 (Andy)
- removed unneeded checks for negative return values in st_lsm6dsx_fusion.c (Andy)
- replaced st_lsm6dsx_sf_set_page function with st_lsm6dsx_sf_page_enable/disable (Andy)
- used reversed xmas tree ordering for local variables (Andy)
- added parentheses to MILLI / MICRO in st_lsm6dsx_sf_write_raw (Andy)
- added check for string truncation in st_lsm6dsx_sf_probe (Andy)
Changes from v2 [2]:
- amended description of patch 2 to point out that there are no supported gyro events (Jonathan)
- removed superfluous parentheses in st_lsm6dsx_fifo_setup (Lorenzo)
- added Lorenzo's acked-by tag to patch 3
- added missing checks of st_lsm6dsx_sf_set_page() return value (Jonathan)
- added comment in st_lsm6dsx_sf_write_raw (Jonathan)
Changes from v1 [1]:
- swapped patches 1 and 2 (Jonathan)
- miscellaneous stylistic changes (Andy)
- fixed usage of MICRO and MILLI constants in st_lsm6dsx_sf_read_raw and st_lsm6dsx_sf_write_raw (Andy)
- replaced scnprintf() with sysfs_emit_at() in st_lsm6dsx_sf_sampling_freq_avail (Andy)
- replaced scnprintf() with snprintf() in st_lsm6dsx_sf_probe (Andy)
- clarified in a comment in st_lsm6dsx_set_fifo_odr() that only internal sensors have a FIFO ODR configuration register (Jonathan)
- modified patch 3 description to explain justification for the extra IIO device (Jonathan)
- moved page lock from st_lsm6dsx_sf_set_page() to the callers (Jonathan)
- s/magnetometer/gyroscope/ in patch 2 description
[0]: https://lore.kernel.org/linux-iio/20260307-iio-fix-timestamp-alignment-v2-4-d1d48fbadbbf@baylibre.com/
[1] https://lore.kernel.org/linux-iio/[email protected]/T/
[2] https://lore.kernel.org/linux-iio/[email protected]/T/
[3] https://lore.kernel.org/linux-iio/[email protected]/T/
[4] https://lore.kernel.org/linux-iio/[email protected]/T/
[5] https://lore.kernel.org/linux-iio/[email protected]/T/
[6] https://lore.kernel.org/linux-iio/[email protected]/T/
[7] https://lore.kernel.org/linux-iio/[email protected]/T/
[8] https://lore.kernel.org/linux-iio/[email protected]/T/
Francesco Lavra (6):
iio: imu: st_lsm6dsx: Fix check for invalid samples from FIFO
iio: Replace 'sign' field with union in struct iio_scan_type
iio: tools: Add support for floating-point types in buffer scan
elements
iio: ABI: Add support for floating-point numbers in buffer scan
elements
iio: ABI: Add quaternion axis modifier
iio: imu: st_lsm6dsx: Add support for rotation sensor
Documentation/ABI/testing/sysfs-bus-iio | 48 ++-- Documentation/driver-api/iio/buffers.rst | 7 +- Documentation/iio/iio_devbuf.rst | 3 +- drivers/iio/imu/st_lsm6dsx/Makefile | 2 +- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 28 +- .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 40 ++- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 58 +++++ .../iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c | 243 ++++++++++++++++++ drivers/iio/industrialio-core.c | 1 + include/linux/iio/iio.h | 30 ++- include/uapi/linux/iio/types.h | 1 + tools/iio/iio_event_monitor.c | 1 + tools/iio/iio_generic_buffer.c | 70 ++++- tools/iio/iio_utils.c | 12 +- tools/iio/iio_utils.h | 4 +- 15 files changed, 495 insertions(+), 53 deletions(-) create mode 100644 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c
Signature · 1 line
2.39.5
PATCH v9 1/6 iio: imu: st_lsm6dsx: Fix check for invalid samples from FIFO
The DRDY_MASK feature implemented in sensor chips marks gyroscope and accelerometer invalid samples (i.e. samples that have been acquired during the settling time of sensor filters) with the special values 0x7FFFh, 0x7FFE, and 0x7FFD.
The driver checks FIFO samples against these special values in order to discard invalid samples; however, it does the check regardless of the type of samples being processed, whereas this feature is specific to gyroscope and accelerometer data. This could cause valid samples to be discarded.
Fix the above check so that it takes into account the type of samples being processed. To avoid casting to __le16 * when checking sample values, clean up the type representation for data read from the FIFO.
--- .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +22 -9
@@ -365,8 +365,6 @@ static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 addr,return 0 ; } -#define ST_LSM6DSX_IIO_BUFF_SIZE (ALIGN(ST_LSM6DSX_SAMPLE_SIZE, \ - sizeof(s64)) + sizeof(s64))/** * st_lsm6dsx_read_fifo() - hw FIFO read routine * @hw: Pointer to instance of struct st_lsm6dsx_hw.
@@ -537,16 +535,24 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) }#define ST_LSM6DSX_INVALID_SAMPLE 0x7ffd +static bool st_lsm6dsx_check_data (u8 tag,__le16 *data) +{ +if ((tag ==ST_LSM6DSX_GYRO_TAG || tag ==ST_LSM6DSX_ACC_TAG ) && + (s16 )le16_to_cpup (data) >=ST_LSM6DSX_INVALID_SAMPLE ) +return false; + +return true; +} +static int st_lsm6dsx_push_tagged_data (struct st_lsm6dsx_hw *hw,u8 tag, -u8 *data,s64 ts) +__le16 *data,s64 ts) { -s16 val =le16_to_cpu (*(__le16 *)data);struct st_lsm6dsx_sensor *sensor;struct iio_dev *iio_dev;/* invalid sample during bootstrap phase */ -if (val >=ST_LSM6DSX_INVALID_SAMPLE ) +if (!st_lsm6dsx_check_data (tag, data))return -EINVAL ;/*
@@ -609,7 +615,13 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw)* must be passed a buffer that is aligned to 8 bytes so * as to allow insertion of a naturally aligned timestamp. */ -u8 iio_buff[ST_LSM6DSX_IIO_BUFF_SIZE ]__aligned(8) ; +struct { +union { +__le16 data[3 ]; +__le32 fifo_ts; + }; +aligned_s64 timestamp; + } iio_buff = { };u8 tag;bool reset_ts = false;int i, err, read_len;
@@ -648,7 +660,7 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw)for (i =0 ; i < pattern_len; i +=ST_LSM6DSX_TAGGED_SAMPLE_SIZE ) { -memcpy (iio_buff, &hw->buff[i +ST_LSM6DSX_TAG_SIZE ], +memcpy (&iio_buff, &hw->buff[i +ST_LSM6DSX_TAG_SIZE ],ST_LSM6DSX_SAMPLE_SIZE ); tag = hw->buff[i] >>3 ;
@@ -659,7 +671,7 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw)* B0 = ts[7:0], B1 = ts[15:8], B2 = ts[23:16], * B3 = ts[31:24] */ - ts =le32_to_cpu (*((__le32 *)iio_buff)); + ts =le32_to_cpu (iio_buff.fifo_ts);/* * check if hw timestamp engine is going to * reset (the sensor generates an interrupt
@@ -670,7 +682,8 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw) reset_ts = true; ts *= hw->ts_gain; }else { -st_lsm6dsx_push_tagged_data (hw, tag, iio_buff, +st_lsm6dsx_push_tagged_data (hw, tag, + iio_buff.data, ts); } }
Signature · 1 line
2.39.5
Re: [PATCH v9 1/6] iio: imu: st_lsm6dsx: Fix check for invalid samples from FIFO
Quoted 12 lines · Francesco Lavra
The
DRDY_MASKfeature implemented in sensor chips marks gyroscope and accelerometer invalid samples (i.e. samples that have been acquired during the settling time of sensor filters) with the special values 0x7FFFh,0x7FFE, and0x7FFD.
The driver checks FIFO samples against these special values in order to discard invalid samples; however, it does the check regardless of the type of samples being processed, whereas this feature is specific to gyroscope and accelerometer data. This could cause valid samples to be discarded.Fix the above check so that it takes into account the type of samples being processed. To avoid casting to
__le16* when checking sample values, clean up the type representation for data read from the FIFO.
...
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) · line 549
Quoted 4 lines
static int
st_lsm6dsx_push_tagged_data(structst_lsm6dsx_hw*hw, u8 tag,drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +1
-1- u8 *data, s64 ts) + __le16 *data, s64 ts)
Dunno why this indentation, but if you need to send a new version, consider
static int st_lsm6dsx_push_tagged_data(struct st_lsm6dsx_hw *hw, u8 tag,
__le16 *data, s64 ts)
OR
static intst_lsm6dsx_push_tagged_data(struct st_lsm6dsx_hw *hw, u8 tag, __le16 *data, s64 ts)
(yes, the second one goes to 83 characters).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v9 1/6] iio: imu: st_lsm6dsx: Fix check for invalid samples from FIFO
Quoted 23 lines · On Tue, 24 Mar 2026 14:17:11 +0200 Andy Shevchenko…
Quoted 12 lines · Francesco Lavra
The
DRDY_MASKfeature implemented in sensor chips marks gyroscope and accelerometer invalid samples (i.e. samples that have been acquired during the settling time of sensor filters) with the special values 0x7FFFh,0x7FFE, and0x7FFD.
The driver checks FIFO samples against these special values in order to discard invalid samples; however, it does the check regardless of the type of samples being processed, whereas this feature is specific to gyroscope and accelerometer data. This could cause valid samples to be discarded.Fix the above check so that it takes into account the type of samples being processed. To avoid casting to
__le16* when checking sample values, clean up the type representation for data read from the FIFO....
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) · line 549
Quoted 4 lines
static int
st_lsm6dsx_push_tagged_data(structst_lsm6dsx_hw*hw, u8 tag,drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +1
-1- u8 *data, s64 ts) + __le16 *data, s64 ts)Dunno why this indentation, but if you need to send a new version, consider
Quoted 3 lines
static int st_lsm6dsx_push_tagged_data(struct
st_lsm6dsx_hw*hw, u8 tag,__le16 *data, s64 ts)
Tweaked to this one.
Quoted 7 lines
OR
static int
st_lsm6dsx_push_tagged_data(struct st_lsm6dsx_hw *hw, u8 tag, __le16 *data, s64 ts)(yes, the second one goes to 83 characters).
PATCH v9 2/6 iio: Replace 'sign' field with union in struct iio_scan_type
In reply to Francesco LavraThis field is used to differentiate between signed and unsigned integers. A following commit will extend its use in order to add support for non- integer scan elements; therefore, replace it with a union that contains a more generic 'format' field. This union will be dropped when all drivers are changed to use the format field.
Opportunistically replace character literals with symbolic constants that represent the set of allowed values for the format field.
--- Documentation/driver-api/iio/buffers.rst | 4 ++-- include/linux/iio/iio.h | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-)
Documentation/driver-api/iio/buffers.rst +2 -2
@@ -78,7 +78,7 @@ fields in iio_chan_spec definition:: /* other members */ int scan_index struct { - char sign; + char format; u8 realbits; u8 storagebits; u8 shift;
@@ -98,7 +98,7 @@ following channel definition:: /* other stuff here */ .scan_index = 0, .scan_type = { - .sign = 's', + .format = IIO_SCAN_FORMAT_SIGNED_INT, .realbits = 12, .storagebits = 16, .shift = 4,
include/linux/iio/iio.h +21 -2
@@ -176,9 +176,25 @@ struct iio_event_spec {unsigned long mask_shared_by_all; }; +/** +* define IIO_SCAN_FORMAT_SIGNED_INT - signed integer data format +* +* &iio_scan_type.format value for signed integers (two's complement). +*/ +#define IIO_SCAN_FORMAT_SIGNED_INT 's' + +/** +* define IIO_SCAN_FORMAT_UNSIGNED_INT - unsigned integer data format +* +* &iio_scan_type.format value for unsigned integers. +*/ +#define IIO_SCAN_FORMAT_UNSIGNED_INT 'u' +/** * struct iio_scan_type - specification for channel data format in buffer -* @sign: 's' or 'u' to specify signed or unsigned +* @sign: Deprecated, use @format instead. +* @format: Data format, can have any of the IIO_SCAN_FORMAT_* +* values. * @realbits: Number of valid bits of data * @storagebits: Realbits + padding * @shift: Shift right by this before masking out realbits.
@@ -189,7 +205,10 @@ struct iio_event_spec {* @endianness: little or big endian */ struct iio_scan_type { -char sign; +union { +char sign; +char format; + };u8 realbits;u8 storagebits;u8 shift;
Signature · 1 line
2.39.5
PATCH v9 3/6 iio: tools: Add support for floating-point types in buffer scan elements
In reply to Francesco LavraA subsequent commit will add floating-point support to the ABI; enhance the iio_generic_buffer tool to be able to parse this new data format.
--- tools/iio/iio_generic_buffer.c | 70 ++++++++++++++++++++++++++++++---- tools/iio/iio_utils.c | 12 +++--- tools/iio/iio_utils.h | 4 +- 3 files changed, 70 insertions(+), 16 deletions(-)
tools/iio/iio_generic_buffer.c +62 -8
@@ -26,6 +26,7 @@#include <string.h> #include <poll.h> #include <endian.h> +#include <float.h> #include <getopt.h> #include <inttypes.h> #include <stdbool.h>
@@ -89,12 +90,19 @@ static void print1byte(uint8_t input, struct iio_channel_info *info)*/ input >>= info->shift; input &= info->mask; -if (info->is_signed) { +switch (info->format) { +case 's' : {int8_t val = (int8_t )(input << (8 - info->bits_used)) >> (8 - info->bits_used);printf ("%05f " , ((float )val + info->offset) * info->scale); - }else { +break ; + } +case 'u' :printf ("%05f " , ((float )input + info->offset) * info->scale); +break ; +case 'f' : +printf ("<invalid 1-byte float> " ); +break ; } }
@@ -112,12 +120,30 @@ static void print2byte(uint16_t input, struct iio_channel_info *info)*/ input >>= info->shift; input &= info->mask; -if (info->is_signed) { +switch (info->format) { +case 's' : {int16_t val = (int16_t )(input << (16 - info->bits_used)) >> (16 - info->bits_used);printf ("%05f " , ((float )val + info->offset) * info->scale); - }else { +break ; + } +case 'u' :printf ("%05f " , ((float )input + info->offset) * info->scale); +break ; +case 'f' : { +#if defined(__FLT16_MAX__) +union { +uint16_t u; +_Float16 f; + } converter; + + converter.u = input; +printf ("%05f " , ((float )converter.f + info->offset) * info->scale); +#else +printf ("<unsupported 2-byte float> " ); +#endif +break ; + } } }
@@ -135,12 +161,26 @@ static void print4byte(uint32_t input, struct iio_channel_info *info)*/ input >>= info->shift; input &= info->mask; -if (info->is_signed) { +switch (info->format) { +case 's' : {int32_t val = (int32_t )(input << (32 - info->bits_used)) >> (32 - info->bits_used);printf ("%05f " , ((float )val + info->offset) * info->scale); - }else { +break ; + } +case 'u' :printf ("%05f " , ((float )input + info->offset) * info->scale); +break ; +case 'f' : { +union { +uint32_t u; +float f; + } converter; + + converter.u = input; +printf ("%05f " , (converter.f + info->offset) * info->scale); +break ; + } } }
@@ -158,7 +198,8 @@ static void print8byte(uint64_t input, struct iio_channel_info *info)*/ input >>= info->shift; input &= info->mask; -if (info->is_signed) { +switch (info->format) { +case 's' : {int64_t val = (int64_t )(input << (64 - info->bits_used)) >> (64 - info->bits_used);/* special case for timestamp */
@@ -167,8 +208,21 @@ static void print8byte(uint64_t input, struct iio_channel_info *info)else printf ("%05f " , ((float )val + info->offset) * info->scale); - }else { +break ; + } +case 'u' :printf ("%05f " , ((float )input + info->offset) * info->scale); +break ; +case 'f' : { +union { +uint64_t u; +double f; + } converter; + + converter.u = input; +printf ("%05f " , (converter.f + info->offset) * info->scale); +break ; + } } }
tools/iio/iio_utils.c +6 -6
@@ -70,7 +70,7 @@ int iioutils_break_up_name(const char *full_name, char **generic_name)/** * iioutils_get_type() - find and process _type attribute data -* @is_signed: output whether channel is signed +* @format: output channel format * @bytes: output how many bytes the channel storage occupies * @bits_used: output number of valid bits of data * @shift: output amount of bits to shift right data before applying bit mask
@@ -83,7 +83,7 @@ int iioutils_break_up_name(const char *full_name, char **generic_name)* * Returns a value >= 0 on success, otherwise a negative error code. **/ -static int iioutils_get_type(unsigned int *is_signed, unsigned int *bytes, +static int iioutils_get_type(char *format, unsigned int *bytes, unsigned int *bits_used, unsigned int *shift, uint64_t *mask, unsigned int *be, const char *device_dir, int buffer_idx,
@@ -93,7 +93,7 @@ static int iioutils_get_type(unsigned int *is_signed, unsigned int *bytes,int ret;DIR *dp;char *scan_el_dir, *builtname, *builtname_generic, *filename =0 ; -char signchar, endianchar; +char formatchar, endianchar;unsigned padint;const struct dirent *ent;
@@ -140,7 +140,7 @@ static int iioutils_get_type(unsigned int *is_signed, unsigned int *bytes, ret =fscanf (sysfsfp,"%ce:%c%u/%u>>%u" , &endianchar, - &signchar, + &formatchar, bits_used, &padint, shift);if (ret <0 ) {
@@ -162,7 +162,7 @@ static int iioutils_get_type(unsigned int *is_signed, unsigned int *bytes,else *mask = (1ULL << *bits_used) -1ULL ; - *is_signed = (signchar =='s' ); + *format = formatchar;if (fclose (sysfsfp)) { ret = -errno; fprintf(stderr, "Failed to close %s\n",
@@ -487,7 +487,7 @@ int build_channel_array(const char *device_dir, int buffer_idx,if ((ret <0 ) && (ret != -ENOENT )) goto error_cleanup_array; - ret = iioutils_get_type(¤t->is_signed, + ret = iioutils_get_type(¤t->format, ¤t->bytes, ¤t->bits_used, ¤t->shift,
tools/iio/iio_utils.h +2 -2
@@ -32,7 +32,7 @@ extern const char *iio_dir;* @shift: amount of bits to shift right data before applying bit mask * @mask: a bit mask for the raw output * @be: flag if data is big endian -* @is_signed: is the raw value stored signed +* @format: format of the raw value * @location: data offset for this channel inside the buffer (in bytes) **/ struct iio_channel_info {
@@ -46,7 +46,7 @@ struct iio_channel_info {unsigned shift;uint64_t mask;unsigned be; -unsigned is_signed; +char format;unsigned location; };
Signature · 1 line
2.39.5
PATCH v9 4/6 iio: ABI: Add support for floating-point numbers in buffer scan elements
In reply to Francesco LavraIn the data storage description of a scan element, the first character after the colon can have the values 's' and 'u' to specify signed and unsigned integers, respectively.
Add 'f' as an allowed value to specify floating-point numbers formatted according to the IEEE 754 standard.
--- Documentation/ABI/testing/sysfs-bus-iio | 33 +++++++++++++----------- Documentation/driver-api/iio/buffers.rst | 3 ++- Documentation/iio/iio_devbuf.rst | 3 ++- include/linux/iio/iio.h | 7 +++++ 4 files changed, 29 insertions(+), 17 deletions(-)
Documentation/ABI/testing/sysfs-bus-iio +18 -15
@@ -1510,21 +1510,24 @@ Contact: [email protected] Description: Description of the scan element data storage within the buffer and hence the form in which it is read from user-space. - Form is [be|le]:[s|u]bits/storagebits[>>shift]. - be or le specifies big or little endian. s or u specifies if - signed (2's complement) or unsigned. bits is the number of bits - of data and storagebits is the space (after padding) that it - occupies in the buffer. shift if specified, is the shift that - needs to be applied prior to masking out unused bits. Some - devices put their data in the middle of the transferred elements - with additional information on both sides. Note that some - devices will have additional information in the unused bits - so to get a clean value, the bits value must be used to mask - the buffer output value appropriately. The storagebits value - also specifies the data alignment. So s48/64>>2 will be a - signed 48 bit integer stored in a 64 bit location aligned to - a 64 bit boundary. To obtain the clean value, shift right 2 - and apply a mask to zero the top 16 bits of the result. + Form is [be|le]:[f|s|u]bits/storagebits[>>shift]. + be or le specifies big or little endian. f means floating-point + (IEEE 754 binary format), s means signed (2's complement), u means + unsigned. bits is the number of bits of data and storagebits is the + space (after padding) that it occupies in the buffer; when using a + floating-point format, bits must be one of the width values defined + in the IEEE 754 standard for binary interchange formats (e.g. 16 + indicates the binary16 format for half-precision numbers). shift, + if specified, is the shift that needs to be applied prior to + masking out unused bits. Some devices put their data in the middle + of the transferred elements with additional information on both + sides. Note that some devices will have additional information in + the unused bits, so to get a clean value the bits value must be + used to mask the buffer output value appropriately. The storagebits + value also specifies the data alignment. So s48/64>>2 will be a + signed 48 bit integer stored in a 64 bit location aligned to a 64 + bit boundary. To obtain the clean value, shift right 2 and apply a + mask to zero the top 16 bits of the result. For other storage combinations this attribute will be extended appropriately.
Documentation/driver-api/iio/buffers.rst +2 -1
@@ -37,9 +37,10 @@ directory contains attributes of the following form: * :file:`index`, the scan_index of the channel. * :file:`type`, description of the scan element data storage within the buffer and hence the form in which it is read from user space. - Format is [be|le]:[s|u]bits/storagebits[Xrepeat][>>shift] . + Format is [be|le]:[f|s|u]bits/storagebits[Xrepeat][>>shift] . * *be* or *le*, specifies big or little endian. + * *f*, specifies if floating-point. * *s* or *u*, specifies if signed (2's complement) or unsigned. * *bits*, is the number of valid data bits. * *storagebits*, is the number of bits (after padding) that it occupies in the
Documentation/iio/iio_devbuf.rst +2 -1
@@ -83,9 +83,10 @@ and the relevant _type attributes to establish the data storage format. Read-only attribute containing the description of the scan element data storage within the buffer and hence the form in which it is read from userspace. Format -is [be|le]:[s|u]bits/storagebits[Xrepeat][>>shift], where: +is [be|le]:[f|s|u]bits/storagebits[Xrepeat][>>shift], where: - **be** or **le** specifies big or little-endian. +- **f** specifies if floating-point. - **s** or **u** specifies if signed (2's complement) or unsigned. - **bits** is the number of valid data bits. - **storagebits** is the number of bits (after padding) that it occupies in the
include/linux/iio/iio.h +7 -0
@@ -190,6 +190,13 @@ struct iio_event_spec {*/ #define IIO_SCAN_FORMAT_UNSIGNED_INT 'u' +/** +* define IIO_SCAN_FORMAT_FLOAT - floating-point data format +* +* &iio_scan_type.format value for IEEE 754 floating-point numbers. +*/ +#define IIO_SCAN_FORMAT_FLOAT 'f' +/** * struct iio_scan_type - specification for channel data format in buffer * @sign: Deprecated, use @format instead.
Signature · 1 line
2.39.5
PATCH v9 5/6 iio: ABI: Add quaternion axis modifier
In reply to Francesco LavraThis modifier applies to the IIO_ROT channel type, and indicates a data representation that specifies the {x, y, z} components of the normalized quaternion vector.
---
The use of this modifier depends on [1] to get the correct sizing of the buffer in userspace.
--- Documentation/ABI/testing/sysfs-bus-iio | 15 +++++++++++++++ drivers/iio/industrialio-core.c | 1 + include/uapi/linux/iio/types.h | 1 + tools/iio/iio_event_monitor.c | 1 + 4 files changed, 18 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +15 -0
@@ -1755,6 +1755,21 @@ Description: measurement from channel Y. Units after application of scale and offset are milliamps. +What: /sys/bus/iio/devices/iio:deviceX/in_rot_quaternionaxis_raw +KernelVersion: 7.1 +Contact: [email protected] +Description: + Raw value of {x, y, z} components of the quaternion vector. These + components represent the axis about which a rotation occurs, and are + subject to the following constraints: + + - the quaternion vector is normalized, i.e. w^2 + x^2 + y^2 + z^2 = 1 + - the rotation angle is within the [-pi, pi] range, i.e. the w + component (which represents the amount of rotation) is non-negative + + These constraints allow the w value to be calculated from the other + components: w = sqrt(1 - (x^2 + y^2 + z^2)). + What: /sys/.../iio:deviceX/in_energy_en What: /sys/.../iio:deviceX/in_distance_en What: /sys/.../iio:deviceX/in_velocity_sqrt(x^2+y^2+z^2)_en
drivers/iio/industrialio-core.c +1 -0
@@ -157,6 +157,7 @@ static const char * const iio_modifier_names[] = { [IIO_MOD_ACTIVE] = "active", [IIO_MOD_REACTIVE] = "reactive", [IIO_MOD_APPARENT] = "apparent", + [IIO_MOD_QUATERNION_AXIS] = "quaternionaxis", };/* relies on pairs of these shared then separate */
include/uapi/linux/iio/types.h +1 -0
@@ -113,6 +113,7 @@ enum iio_modifier {IIO_MOD_ACTIVE ,IIO_MOD_REACTIVE ,IIO_MOD_APPARENT , + IIO_MOD_QUATERNION_AXIS, }; enum iio_event_type {
tools/iio/iio_event_monitor.c +1 -0
@@ -145,6 +145,7 @@ static const char * const iio_modifier_names[] = { [IIO_MOD_ACTIVE] = "active", [IIO_MOD_REACTIVE] = "reactive", [IIO_MOD_APPARENT] = "apparent", + [IIO_MOD_QUATERNION_AXIS] = "quaternionaxis", };static bool event_is_known (struct iio_event_data *event)
Signature · 1 line
2.39.5
PATCH v9 6/6 iio: imu: st_lsm6dsx: Add support for rotation sensor
In reply to Francesco LavraSome 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 LSM6DSV16X.
--- drivers/iio/imu/st_lsm6dsx/Makefile | 2 +- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 28 +- .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 9 +- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 58 +++++ .../iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c | 243 ++++++++++++++++++ 5 files changed, 333 insertions(+), 7 deletions(-) create mode 100644 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c
drivers/iio/imu/st_lsm6dsx/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only st_lsm6dsx-y := st_lsm6dsx_core.o st_lsm6dsx_buffer.o \ - st_lsm6dsx_shub.o + st_lsm6dsx_shub.o st_lsm6dsx_fusion.o obj-$(CONFIG_IIO_ST_LSM6DSX) += st_lsm6dsx.o obj-$(CONFIG_IIO_ST_LSM6DSX_I2C) += st_lsm6dsx_i2c.o
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +23 -5
@@ -294,6 +294,7 @@ enum st_lsm6dsx_sensor_id {ST_LSM6DSX_ID_EXT0 ,ST_LSM6DSX_ID_EXT1 ,ST_LSM6DSX_ID_EXT2 , +ST_LSM6DSX_ID_FUSION , ST_LSM6DSX_ID_MAX };
@@ -301,6 +302,17 @@ enum st_lsm6dsx_ext_sensor_id { ST_LSM6DSX_ID_MAGN, }; +struct st_lsm6dsx_fusion_settings { +const struct iio_chan_spec *chan; +int chan_len; +struct st_lsm6dsx_reg odr_reg; +int odr_hz[ST_LSM6DSX_ODR_LIST_SIZE ]; +int odr_len; +struct st_lsm6dsx_reg fifo_enable; +struct st_lsm6dsx_reg page_mux; +struct st_lsm6dsx_reg enable; +}; +/** * struct st_lsm6dsx_ext_dev_settings - i2c controller slave settings * @i2c_addr: I2c slave address list.
@@ -388,6 +400,7 @@ struct st_lsm6dsx_settings {struct st_lsm6dsx_hw_ts_settings ts_settings;struct st_lsm6dsx_shub_settings shub_settings;struct st_lsm6dsx_event_settings event_settings; +struct st_lsm6dsx_fusion_settings fusion_settings; };enum st_lsm6dsx_fifo_mode {
@@ -510,6 +523,9 @@ int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u32 odr, u8 *val);int st_lsm6dsx_shub_probe (struct st_lsm6dsx_hw *hw,const char *name);int st_lsm6dsx_shub_set_enable (struct st_lsm6dsx_sensor *sensor,bool enable);int st_lsm6dsx_shub_read_output (struct st_lsm6dsx_hw *hw,u8 *data,int len); +int st_lsm6dsx_fusion_probe (struct st_lsm6dsx_hw *hw,const char *name); +int st_lsm6dsx_fusion_set_enable (struct st_lsm6dsx_sensor *sensor,bool enable); +int st_lsm6dsx_fusion_set_odr (struct st_lsm6dsx_sensor *sensor,bool enable);int st_lsm6dsx_set_page (struct st_lsm6dsx_hw *hw,bool enable); static inline int
@@ -564,12 +580,14 @@ st_lsm6dsx_get_mount_matrix(const struct iio_dev *iio_dev,static inline int st_lsm6dsx_device_set_enable (struct st_lsm6dsx_sensor *sensor,bool enable) { -if (sensor->id ==ST_LSM6DSX_ID_EXT0 || - sensor->id ==ST_LSM6DSX_ID_EXT1 || - sensor->id ==ST_LSM6DSX_ID_EXT2 ) +switch (sensor->id) { + case ST_LSM6DSX_ID_EXT0 ... ST_LSM6DSX_ID_EXT2:return st_lsm6dsx_shub_set_enable (sensor, enable); - -return st_lsm6dsx_sensor_set_enable (sensor, enable); +case ST_LSM6DSX_ID_FUSION : +return st_lsm6dsx_fusion_set_enable (sensor, enable); +default : +return st_lsm6dsx_sensor_set_enable (sensor, enable); + } } static const
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +8 -1
@@ -88,6 +88,7 @@ enum st_lsm6dsx_fifo_tag {ST_LSM6DSX_EXT0_TAG =0x0f ,ST_LSM6DSX_EXT1_TAG =0x10 ,ST_LSM6DSX_EXT2_TAG =0x11 , + ST_LSM6DSX_ROT_TAG = 0x13, }; static const
@@ -226,8 +227,11 @@ static int st_lsm6dsx_set_fifo_odr(struct st_lsm6dsx_sensor *sensor,u8 data;/* Only internal sensors have a FIFO ODR configuration register. */ -if (sensor->id >=ARRAY_SIZE (hw->settings->batch)) +if (sensor->id >=ARRAY_SIZE (hw->settings->batch)) { +if (sensor->id ==ST_LSM6DSX_ID_FUSION ) +return st_lsm6dsx_fusion_set_odr (sensor, enable);return 0 ; + } batch_reg = &hw->settings->batch[sensor->id];if (batch_reg->addr) {
@@ -586,6 +590,9 @@ 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 : + iio_dev = hw->iio_devs[ST_LSM6DSX_ID_FUSION ]; +break ;default :return -EINVAL ; }
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +58 -0
82 lines not on this page · raw message
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c new file +243 -0
243 lines not on this page · raw message
Signature · 1 line
2.39.5
Re: [PATCH v9 6/6] iio: imu: st_lsm6dsx: Add support for rotation sensor
Quoted 18 lines · On Tue, 24 Mar 2026 09:48:07 +0100 Francesco Lavra <[email protected]> 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 structst_lsm6dsx_settings. Inst_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.
Quoted 4 lines
Tested on LSM6DSV16X.
Signed-off-by Francesco Lavra <[email protected]>Acked-by Lorenzo Bianconi <[email protected]>
One trivial thing. But don't resend for that. Assuming nothing else comes up I'll tweak it whilst applying. Same for Andy's line wrap comment.
thanks,
Jonathan
Quoted 18 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c new file +11
-0@@ -0,0 +1,243 @@ + +int st_lsm6dsx_fusion_set_odr (struct st_lsm6dsx_sensor *sensor,bool enable) +{ +struct st_lsm6dsx_hw *hw = sensor->hw; +int err; + +guard (mutex)(&hw->page_lock); + + err =st_lsm6dsx_fusion_page_enable (hw); +if (err) +return err;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c line 137
Quoted 10 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c new file +10
-0+ + err =st_lsm6dsx_fusion_set_odr_locked (sensor, enable); +if (err) { +st_lsm6dsx_fusion_page_disable (hw); +return err; + } + +return st_lsm6dsx_fusion_page_disable (hw); + +out:
Stray. If nothing else comes up I'll drop this whilst applying.
Quoted 1 line
+}
Jonathan Cameron
maintainerRe: [PATCH v9 6/6] iio: imu: st_lsm6dsx: Add support for rotation sensor
Quoted 21 lines · On Wed, 25 Mar 2026 14:55:26 +0000 Jonathan Cameron…
Quoted 18 lines · On Tue, 24 Mar 2026 09:48:07 +0100 Francesco Lavra <[email protected]> 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 structst_lsm6dsx_settings. Inst_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.
Quoted 7 lines
Quoted 4 lines
Tested on LSM6DSV16X.
Signed-off-by Francesco Lavra <[email protected]>Acked-by Lorenzo Bianconi <[email protected]>One trivial thing. But don't resend for that. Assuming nothing else comes up I'll tweak it whilst applying. Same for Andy's line wrap comment.
Ah. I tried to pick up the series but we have a dependency on a fix that hasn't quite made it upstream yet and I don't want the complexity of merging my own fixes branch in until I know that made it upstream.
Sorry, I don't think I can get this merged this cycle unless we go to rc8. Will get it queued from start of next cycle.
Jonathan
Quoted 35 lines
thanks,
Jonathan
Quoted 18 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c new file +11
-0@@ -0,0 +1,243 @@ + +int st_lsm6dsx_fusion_set_odr (struct st_lsm6dsx_sensor *sensor,bool enable) +{ +struct st_lsm6dsx_hw *hw = sensor->hw; +int err; + +guard (mutex)(&hw->page_lock); + + err =st_lsm6dsx_fusion_page_enable (hw); +if (err) +return err;drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c line 137
Quoted 10 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c new file +10
-0+ + err =st_lsm6dsx_fusion_set_odr_locked (sensor, enable); +if (err) { +st_lsm6dsx_fusion_page_disable (hw); +return err; + } + +return st_lsm6dsx_fusion_page_disable (hw); + +out:Stray. If nothing else comes up I'll drop this whilst applying.
Quoted 1 line
+}
kernel test robot
build botRe: [PATCH v9 6/6] iio: imu: st_lsm6dsx: Add support for rotation sensor
In reply to Francesco Lavrakernel test robot noticed the following build errors:
Hi Francesco,
kernel test robot noticed the following build errors:
[auto build test ERROR on next-20260323]
[cannot apply to jic23-iio/togreg linus/master v7.0-rc5 v7.0-rc4 v7.0-rc3 v7.0-rc5] [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#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Francesco-Lavra/iio-imu-st_lsm6dsx-Fix-check-for-invalid-samples-from-FIFO/20260325-021519 base: next-20260323 patch link: https://lore.kernel.org/r/20260324084808.654118-1-flavra%40baylibre.com patch subject: [PATCH v9 6/6] iio: imu: st_lsm6dsx: Add support for rotation sensor config: parisc-randconfig-r072-20260326 (https://download.01.org/0day-ci/archive/20260326/[email protected]/config) compiler: hppa-linux-gcc (GCC) 8.5.0 smatch: v0.5.0-9004-gb810ac53 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260326/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All error/warnings (new ones prefixed by >>):
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c: In function 'st_lsm6dsx_fusion_set_odr':
>> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c:137:1: error: label at end of compound statement
out:
^~~
>> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c:137:1: warning: label 'out' defined but not used [-Wunused-label]vim +137 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c
117
118 int st_lsm6dsx_fusion_set_odr(struct st_lsm6dsx_sensor *sensor, bool enable)
119 {
120 struct st_lsm6dsx_hw *hw = sensor->hw;
121 int err;
122
123 guard(mutex)(&hw->page_lock);
124
125 err = st_lsm6dsx_fusion_page_enable(hw);
126 if (err)
127 return err;
128
129 err = st_lsm6dsx_fusion_set_odr_locked(sensor, enable);
130 if (err) {
131 st_lsm6dsx_fusion_page_disable(hw);
132 return err;
133 }
134
135 return st_lsm6dsx_fusion_page_disable(hw);
136
> 137 out:
138 }
139
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v9 6/6] iio: imu: st_lsm6dsx: Add support for rotation sensor
In reply to Francesco Lavrakernel test robot noticed the following build warnings:
Hi Francesco,
kernel test robot noticed the following build warnings:
[auto build test WARNING on next-20260323]
[cannot apply to jic23-iio/togreg linus/master v7.0-rc5 v7.0-rc4 v7.0-rc3 v7.0-rc5] [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#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Francesco-Lavra/iio-imu-st_lsm6dsx-Fix-check-for-invalid-samples-from-FIFO/20260325-021519 base: next-20260323 patch link: https://lore.kernel.org/r/20260324084808.654118-1-flavra%40baylibre.com patch subject: [PATCH v9 6/6] iio: imu: st_lsm6dsx: Add support for rotation sensor config: arm-randconfig-001-20260326 (https://download.01.org/0day-ci/archive/20260326/[email protected]/config) compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 054e11d1a17e5ba88bb1a8ef32fad3346e80b186) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260326/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c:138:1: warning: label at end of compound statement is a C23 extension [-Wc23-extensions]
138 | }
| ^
>> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c:137:1: warning: unused label 'out' [-Wunused-label]
137 | out:
| ^~~~2 warnings generated.
vim +138 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c
117
118 int st_lsm6dsx_fusion_set_odr(struct st_lsm6dsx_sensor *sensor, bool enable)
119 {
120 struct st_lsm6dsx_hw *hw = sensor->hw;
121 int err;
122
123 guard(mutex)(&hw->page_lock);
124
125 err = st_lsm6dsx_fusion_page_enable(hw);
126 if (err)
127 return err;
128
129 err = st_lsm6dsx_fusion_set_odr_locked(sensor, enable);
130 if (err) {
131 st_lsm6dsx_fusion_page_disable(hw);
132 return err;
133 }
134
135 return st_lsm6dsx_fusion_page_disable(hw);
136
> 137 out: > 138 }
139
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v9 6/6] iio: imu: st_lsm6dsx: Add support for rotation sensor
In reply to Francesco Lavrakernel test robot noticed the following build warnings:
Hi Francesco,
kernel test robot noticed the following build warnings:
[auto build test WARNING on next-20260323]
[cannot apply to jic23-iio/togreg linus/master v7.0-rc5 v7.0-rc4 v7.0-rc3 v7.0-rc5] [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#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Francesco-Lavra/iio-imu-st_lsm6dsx-Fix-check-for-invalid-samples-from-FIFO/20260325-021519 base: next-20260323 patch link: https://lore.kernel.org/r/20260324084808.654118-1-flavra%40baylibre.com patch subject: [PATCH v9 6/6] iio: imu: st_lsm6dsx: Add support for rotation sensor config: hexagon-allmodconfig (https://download.01.org/0day-ci/archive/20260326/[email protected]/config) compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260326/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c:138:1: warning: label at end of compound statement is a C2x extension [-Wc2x-extensions]
138 | }
| ^
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c:137:1: warning: unused label 'out' [-Wunused-label]
137 | out:
| ^~~~2 warnings generated.
vim +138 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c
117
118 int st_lsm6dsx_fusion_set_odr(struct st_lsm6dsx_sensor *sensor, bool enable)
119 {
120 struct st_lsm6dsx_hw *hw = sensor->hw;
121 int err;
122
123 guard(mutex)(&hw->page_lock);
124
125 err = st_lsm6dsx_fusion_page_enable(hw);
126 if (err)
127 return err;
128
129 err = st_lsm6dsx_fusion_set_odr_locked(sensor, enable);
130 if (err) {
131 st_lsm6dsx_fusion_page_disable(hw);
132 return err;
133 }
134
135 return st_lsm6dsx_fusion_page_disable(hw);
136
137 out:
> 138 }
139
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Jonathan Cameron
maintainerQuoted 7 lines · On Tue, 24 Mar 2026 09:46:55 +0100 Francesco Lavra <[email protected]> wrote:
This series adds support for the rotation sensor functionality present in some chips from the ST LSM6DSX IMU family.
The IIO ABI has been amended to allow the use of floating-point data and a "quaternion axis" channel modifier in IIO buffers.The use of the new modifier depends on [0] to get the correct sizing of the buffer in userspace.
Applied to the testing branch of iio.git with minor tweaks to fix up that stray label in patch 6 and the code alignment suggestion Andy made in patch 1. Note this is next cycle material, so I'll be rebasing the tree on rc1 once available and only then will it go out as togreg and show up in linux-next.
Thanks,
Jonathan
Quoted 141 lines
Tested on LSM6DSV16X.
Changes from v8 [8]:
- changed comments for IIO_SCAN_FORMAT_* macros to use proper kernel doc format with one comment per macro (David)
- intools/iio, added error print if 1-byte floats are encountered and if 2-byte floats are encountered when unsupported (David)
- intools/iio, renamed signchar variable to formatchar (David)
- added David's Reviewed-by tag to patch 5
- inst_lsm6dsx_fusion.c, avoided mixing cleanup and gotos by adding a helper function (Jonathan)
- inst_lsm6dsx_fusion.c, removed leading double spaces in comment (Jonathan)
- inST_LSM6DSX_CHANNEL_ROTmacro, replaced literal 'f' withIIO_SCAN_FORMAT_FLOATChanges from v7 [7]:
- added Lorenzo's Acked-by tag to patch 1
- inst_lsm6dsx_buffer.c, addedst_lsm6dsx_check_data()helper function (Lorenzo)
- added definition of IIO_SCAN_FORMAT_* symbolic constants to restrict flexibility of what can go in .format (Jonathan)
- re-added @sign description in kernel.doc comment for
structiio_scan_type, mentioning that @format should be used in new code (Jonathan)
- intools/iio/iio_generic_buffer, replaced legacy__fp16type with standard-compliant_Float16(David)
- intools/iio/iio_generic_buffer, added check for compiler support (David), so that compilation does not fail with compilers that don't support_Float16: tested with gcc for x86-64 (supported), for aarch64 (supported), for riscv-64 (not supported), clang for x86-64 (not supported)
- intols/iio/iio_utils.h, replaced unsigned with char type forformatfield in structiio_channel_info(David)
- renamed "partial quaternion" modifier to "quaternion axis"
- moved new modifier value at the end of enumiio_modifier(David)
- squashed the two words together in the modifier name (Jonathan)
- in ABI doc for new modifier, fixed typo and angle units (David)
- in ABI doc for new modifier, fixed kernel-doc warning (kernel test robot)
- inst_lsm6dsx_fusion.c, added missing header includes (Andy)Changes from v6 [6]:
- dropped patches 1 and 2 (already picked up by Jonathan)
- added floating-point support to iio-tools (Andy)
- replacedsignfield in structiio_scan_typewith union instead offormatfield (David, Jonathan)
- changed [s|u|f] to [f|s|u] in ABI and driver documentation files (Andy)
- removedIIO_CUSTOMchannel type in favor ofIIO_MOD_PARTIAL_QUATERNIONmodifier (David, Andy)
- replaced "sf" with "fusion" in type, variable and function names (David)
- added copyright statement inst_lsm6dsx_fusion.c(David)
- addedretvariable inst_lsm6dsx_fusion_probe()for better readability (Andy)
- modified data structure holding the list of available frequencies in order to replace device attribute with .read_avail callback (David)Changes from v5 [5]:
- cleaned up FIFO data representation inst_lsm6dsx_read_tagged_fifo()to avoid casting (Andy, Jonathan)
- renamed 'sign' field toformatin structiio_scan_type
- added support for IEEE 754 floating-point format in buffer scan elements
- added custom data type in the ABI (IIO_CUSTOMin enumiio_chan_type) (Jonathan)
- added driver document inDocumentation/iio/(Jonathan)Changes from v4 [4]:
- changed data parameter inst_lsm6dsx_push_tagged_data()to__le16* (Andy)Changes from v3 [3]:
- added patch 3 (Andy)
- removed unneeded checks for negative return values inst_lsm6dsx_fusion.c(Andy)
- replacedst_lsm6dsx_sf_set_pagefunction with st_lsm6dsx_sf_page_enable/disable (Andy)
- used reversed xmas tree ordering for local variables (Andy)
- added parentheses to MILLI / MICRO inst_lsm6dsx_sf_write_raw(Andy)
- added check for string truncation inst_lsm6dsx_sf_probe(Andy)Changes from v2 [2]:
- amended description of patch 2 to point out that there are no supported gyro events (Jonathan)
- removed superfluous parentheses inst_lsm6dsx_fifo_setup(Lorenzo)
- added Lorenzo's acked-by tag to patch 3
- added missing checks ofst_lsm6dsx_sf_set_page()return value (Jonathan)
- added comment inst_lsm6dsx_sf_write_raw(Jonathan)Changes from v1 [1]:
- swapped patches 1 and 2 (Jonathan)
- miscellaneous stylistic changes (Andy)
- fixed usage of MICRO and MILLI constants inst_lsm6dsx_sf_read_rawandst_lsm6dsx_sf_write_raw(Andy)
- replacedscnprintf()withsysfs_emit_at()inst_lsm6dsx_sf_sampling_freq_avail(Andy)
- replacedscnprintf()withsnprintf()inst_lsm6dsx_sf_probe(Andy)
- clarified in a comment inst_lsm6dsx_set_fifo_odr()that only internal sensors have a FIFO ODR configuration register (Jonathan)
- modified patch 3 description to explain justification for the extra IIO device (Jonathan)
- moved page lock fromst_lsm6dsx_sf_set_page()to the callers (Jonathan)
- s/magnetometer/gyroscope/ in patch 2 description[0]: https://lore.kernel.org/linux-iio/20260307-iio-fix-timestamp-alignment-v2-4-d1d48fbadbbf@baylibre.com/
[1] https://lore.kernel.org/linux-iio/[email protected]/T/
[2] https://lore.kernel.org/linux-iio/[email protected]/T/
[3] https://lore.kernel.org/linux-iio/[email protected]/T/
[4] https://lore.kernel.org/linux-iio/[email protected]/T/
[5] https://lore.kernel.org/linux-iio/[email protected]/T/
[6] https://lore.kernel.org/linux-iio/[email protected]/T/
[7] https://lore.kernel.org/linux-iio/[email protected]/T/
[8] https://lore.kernel.org/linux-iio/[email protected]/T/Francesco Lavra (6):
iio: imu:st_lsm6dsx: Fix check for invalid samples from FIFO
iio: Replace 'sign' field with union in structiio_scan_type
iio: tools: Add support for floating-point types in buffer scan
elements
iio: ABI: Add support for floating-point numbers in buffer scan
elements
iio: ABI: Add quaternion axis modifier
iio: imu:st_lsm6dsx: Add support for rotation sensorDocumentation/ABI/testing/sysfs-bus-iio | 48 ++-- Documentation/driver-api/iio/buffers.rst | 7 +- Documentation/iio/iio_devbuf.rst | 3 +- drivers/iio/imu/st_lsm6dsx/Makefile | 2 +- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 28 +- .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 40 ++- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 58 +++++ .../iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c | 243 ++++++++++++++++++ drivers/iio/industrialio-core.c | 1 + include/linux/iio/iio.h | 30 ++- include/uapi/linux/iio/types.h | 1 + tools/iio/iio_event_monitor.c | 1 + tools/iio/iio_generic_buffer.c | 70 ++++- tools/iio/iio_utils.c | 12 +- tools/iio/iio_utils.h | 4 +- 15 files changed, 495 insertions(+), 53 deletions(-) create mode 100644 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c