Re: [PATCH v5 3/6] iio: imu: inv_icm42607: Initialize gyro based on chip_info

From: Andy Shevchenko

Date: Fri Oct 02 2026 - 09:09:01 EST


On Fri, Oct 02, 2026 at 01:54:27PM +0200, Kanak Shilledar wrote:
> Update the chip_info struct with a new `has_gyro` property to support,
> devices which do not have gyro functionality. This is a precursor to the
> next commit which adds support for the Invensense, ICM-42370-P. It is
> similar to the existing device except it only has accelerometer. Check
> all operations related to gyro with the boolean.

...

> int ret;
>
> - val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, conf->gyro.mode);
> - val |= FIELD_PREP(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, conf->accel.mode);
> + val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, conf->accel.mode);
> + if (st->hw->has_gyro)
> + val |= FIELD_PREP(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, conf->gyro.mode);

Personally I found if-else slightly better as one needs no detour to understand
the whole value.

if (st->hw->has_gyro)
val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, conf->accel.mode) |
FIELD_PREP(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, conf->gyro.mode);
else
val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, conf->accel.mode);

> ret = regmap_write(st->map, INV_ICM42607_REG_PWR_MGMT0, val);
> if (ret)
> return ret;

...

> + if (st->hw->has_gyro) {
> + val = FIELD_PREP(INV_ICM42607_GYRO_CONFIG0_FS_SEL_MASK, conf->gyro.fs);
> + val |= FIELD_PREP(INV_ICM42607_GYRO_CONFIG0_ODR_MASK, conf->gyro.odr);

No need to have two assignments, do it at once.

> + ret = regmap_write(st->map, INV_ICM42607_REG_GYRO_CONFIG0, val);
> + if (ret)
> + return ret;
> + }

--
With Best Regards,
Andy Shevchenko