Re: [PATCH v4 4/9] iio: imu: inv_icm45600: add IMU IIO gyroscope device

From: Jonathan Cameron
Date: Sat Aug 16 2025 - 08:08:43 EST


On Thu, 14 Aug 2025 08:57:18 +0000
Remi Buisson via B4 Relay <devnull+remi.buisson.tdk.com@xxxxxxxxxx> wrote:

> From: Remi Buisson <remi.buisson@xxxxxxx>
>
> Add IIO device for gyroscope sensor
> with data polling interface and FIFO parsing.
> Attributes: raw, scale, sampling_frequency, calibbias.
> Temperature is available as a processed channel.
>
> Signed-off-by: Remi Buisson <remi.buisson@xxxxxxx>
A few minor comments.

> diff --git a/drivers/iio/imu/inv_icm45600/inv_icm45600_gyro.c b/drivers/iio/imu/inv_icm45600/inv_icm45600_gyro.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..7a5a2ce77f3e176bdcb5657c0b8d547024d04930
> --- /dev/null
> +++ b/drivers/iio/imu/inv_icm45600/inv_icm45600_gyro.c

> +int inv_icm45600_gyro_parse_fifo(struct iio_dev *indio_dev)

Ah. This is where this comes in. Add header definition in this
patch as well.

> +{
> + struct inv_icm45600_state *st = iio_device_get_drvdata(indio_dev);
> + struct inv_icm45600_sensor_state *gyro_st = iio_priv(indio_dev);
> + struct inv_sensors_timestamp *ts = &gyro_st->ts;
> + ssize_t i, size;
> + unsigned int no;
> +
> + /* parse all fifo packets */
> + for (i = 0, no = 0; i < st->fifo.count; i += size, ++no) {
> + struct inv_icm45600_gyro_buffer buffer = { };
> + const struct inv_icm45600_fifo_sensor_data *accel, *gyro;
> + const __le16 *timestamp;
> + const s8 *temp;
> + unsigned int odr;
> + s64 ts_val;
> +
> + size = inv_icm45600_fifo_decode_packet(&st->fifo.data[i],

can drag size into this scope as well.

> + &accel, &gyro, &temp, &timestamp, &odr);
> + /* quit if error or FIFO is empty */
> + if (size <= 0)
> + return size;
> +
> + /* skip packet if no gyro data or data is invalid */
> + if (gyro == NULL || !inv_icm45600_fifo_is_data_valid(gyro))
> + continue;
> +
> + /* update odr */
> + if (odr & INV_ICM45600_SENSOR_GYRO)
> + inv_sensors_timestamp_apply_odr(ts, st->fifo.period,
> + st->fifo.nb.total, no);
> +
> + memcpy(&buffer.gyro, gyro, sizeof(buffer.gyro));
> + /* convert 8 bits FIFO temperature in high resolution format */
> + buffer.temp = temp ? (*temp * 64) : 0;
> + ts_val = inv_sensors_timestamp_pop(ts);
> + iio_push_to_buffers_with_timestamp(indio_dev, &buffer, ts_val);

Please switch to new iio_push_to_buffers_with_ts().
I want to get rid of the with_timestamp() version eventually as we might as well
always provide the buffer size.

> + }
> +
> + return 0;
> +}
>