Re: [PATCH v7 4/7] iio: imu: inv_icm42607: Initialize gyro based on chip_info

From: Andy Shevchenko

Date: Mon Oct 26 2026 - 09:14:02 EST


On Mon, Oct 26, 2026 at 12:02:52PM +0100, 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 for
> adding 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. Replace all the implicit comparision
> checks with explicit to make it easier to follow the code flow.

...

> odr_us = 0;
> - if (accel && !oldaccel) {
> + if (accel != INV_ICM42607_SENSOR_MODE_OFF &&
> + oldaccel == INV_ICM42607_SENSOR_MODE_OFF) {

Broken indentation.

> sleepval_us = max(sleepval_us, INV_ICM42607_ACCEL_STARTUP_TIME_US);
> odr_us = max(odr_us, inv_icm42607_odr_to_period_us(st->conf.accel.odr));
> }

> - if (gyro && !oldgyro) {
> + if (gyro != INV_ICM42607_SENSOR_MODE_OFF &&
> + oldgyro == INV_ICM42607_SENSOR_MODE_OFF) {

Ditto.

> sleepval_us = max(sleepval_us, INV_ICM42607_GYRO_STARTUP_TIME_US);
> odr_us = max(odr_us, inv_icm42607_odr_to_period_us(st->conf.gyro.odr));
> /* Track the earliest we can turn off the gyroscope. */

...

> + 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);

Swap them to make lines shorter

val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, conf->gyro.mode) |
FIELD_PREP(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, conf->accel.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) |
> + FIELD_PREP(INV_ICM42607_GYRO_CONFIG0_ODR_MASK, conf->gyro.odr);
> + ret = regmap_write(st->map, INV_ICM42607_REG_GYRO_CONFIG0, val);
> + if (ret)
> + return ret;
> + }

Use same trick.

...

> + val = FIELD_PREP(INV_ICM42607_ACCEL_CONFIG0_FS_SEL_MASK, conf->accel.fs) |
> + FIELD_PREP(INV_ICM42607_ACCEL_CONFIG0_ODR_MASK, conf->accel.odr);

Ditto.

...

> - ret = inv_icm42607_set_pwr_mgmt0(st, st->conf.gyro.mode,
> + ret = inv_icm42607_set_sensor_modes(st, st->conf.gyro.mode,
> st->conf.accel.mode);

Broken indentation.

> if (ret)
> dev_err(dev, "Unable to turn off sensors\n");

--
With Best Regards,
Andy Shevchenko