[PATCH V15 7/9] iio: imu: inv_icm42607: Add Gyroscope to icm42607
Jonathan Cameron
jic23 at kernel.org
Wed Jul 1 12:28:15 PDT 2026
On Fri, 26 Jun 2026 11:12:28 -0500
Chris Morgan <macroalpha82 at gmail.com> wrote:
> From: Chris Morgan <macromorgan at hotmail.com>
>
> Add gyroscope functions to the icm42607 driver.
>
> Signed-off-by: Chris Morgan <macromorgan at hotmail.com>
Similar comments to those in the accel driver.
Thanks,
Jonathan
> diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c
> new file mode 100644
> index 000000000000..c7215b3826ad
> --- /dev/null
> +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c
> +static int inv_icm42607_gyro_read_odr(struct inv_icm42607_state *st,
> + int *val, int *val2)
> +{
> + unsigned int odr;
> + unsigned int i;
> +
> + guard(mutex)(&st->lock);
> +
> + odr = st->conf.gyro.odr;
> +
> + for (i = 5; i < ARRAY_SIZE(inv_icm42607_gyro_odr); ++i) {
> + if (i == odr)
As below.
> +
> +static int inv_icm42607_gyro_write_odr(struct iio_dev *indio_dev,
> + int val, int val2)
> +{
> + struct inv_icm42607_state *st = iio_device_get_drvdata(indio_dev);
> + struct device *dev = regmap_get_device(st->map);
> + unsigned int idx;
> + struct inv_icm42607_sensor_conf conf = INV_ICM42607_SENSOR_CONF_INIT;
> + int ret;
> +
> + for (idx = 5; idx < ARRAY_SIZE(inv_icm42607_gyro_odr); ++idx) {
Similar comments to accel. Use the appropriate define for that 5 and
post increment.
> + if (val == inv_icm42607_gyro_odr[idx][0] &&
> + val2 == inv_icm42607_gyro_odr[idx][1])
> + break;
> + }
> +static int inv_icm42607_gyro_read_avail(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + const int **vals,
> + int *type, int *length, long mask)
> +{
> + if (chan->type != IIO_ANGL_VEL)
This was the one sashiko noted was less than ideal as it rules out
reading this for temperature channels - in practice that doesn't happen
but that is due to an internal detail of how we create shared_by_all
attributes. The code should support reading for temperature channels as well.
> + return -EINVAL;
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_SCALE:
> + *vals = (const int *)inv_icm42607_gyro_scale_nano;
> + *type = IIO_VAL_INT_PLUS_NANO;
> + *length = ARRAY_SIZE(inv_icm42607_gyro_scale_nano) * 2;
> + return IIO_AVAIL_LIST;
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + *vals = (const int *)inv_icm42607_gyro_odr[5];
> + *type = IIO_VAL_INT_PLUS_MICRO;
> + *length = (ARRAY_SIZE(inv_icm42607_gyro_odr) - 5) * 2;
> + return IIO_AVAIL_LIST;
> + default:
> + return -EINVAL;
> + }
> +}
More information about the Linux-rockchip
mailing list