[PATCH v16 07/10] iio: imu: inv_icm42607: Add Accelerometer for icm42607

Andy Shevchenko andriy.shevchenko at intel.com
Tue Jul 14 04:21:49 PDT 2026


On Tue, Jul 14, 2026 at 02:20:48PM +0300, Andy Shevchenko wrote:
> On Mon, Jul 13, 2026 at 04:58:37PM -0500, Chris Morgan wrote:

...

> > +int inv_icm42607_read_sensor(struct iio_dev *indio_dev,
> > +			     struct iio_chan_spec const *chan,
> > +			     s16 *val)
> > +{
> > +	struct inv_icm42607_sensor_conf conf = INV_ICM42607_SENSOR_CONF_INIT;
> > +	struct inv_icm42607_state *st = iio_device_get_drvdata(indio_dev);
> > +	struct inv_icm42607_sensor_state *sensor_st = iio_priv(indio_dev);
> > +	struct device *dev = regmap_get_device(st->map);
> > +	unsigned int reg;
> 
> > +	u8 data[2];
> 
> Define using the correct type. AFAICS it should be __be16 data;
> 
> > +	int ret;
> > +
> > +	if ((chan->type != IIO_ANGL_VEL) && (chan->type != IIO_ACCEL))
> > +		return -EINVAL;
> > +
> > +	switch (chan->channel2) {
> > +	case IIO_MOD_X:
> > +		if (chan->type == IIO_ANGL_VEL)
> > +			reg = INV_ICM42607_REG_GYRO_DATA_X1;
> > +		else
> > +			reg = INV_ICM42607_REG_ACCEL_DATA_X1;
> > +		break;
> > +	case IIO_MOD_Y:
> > +		if (chan->type == IIO_ANGL_VEL)
> > +			reg = INV_ICM42607_REG_GYRO_DATA_Y1;
> > +		else
> > +			reg = INV_ICM42607_REG_ACCEL_DATA_Y1;
> > +		break;
> > +	case IIO_MOD_Z:
> > +		if (chan->type == IIO_ANGL_VEL)
> > +			reg = INV_ICM42607_REG_GYRO_DATA_Z1;
> > +		else
> > +			reg = INV_ICM42607_REG_ACCEL_DATA_Z1;
> > +		break;
> > +	default:
> > +		return -EINVAL;
> > +	}
> > +
> > +	PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev, pm);
> > +	ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
> > +	if (ret)
> > +		return ret;
> > +
> > +	guard(mutex)(&st->lock);
> > +
> > +	/* enable sensor */
> > +	conf.mode = sensor_st->power_mode;
> > +	conf.filter = sensor_st->filter;
> > +	ret = inv_icm42607_set_sensor_conf(st, &conf, chan->type);
> > +	if (ret)
> > +		return ret;
> > +
> > +	/* read sensor register data */
> > +	ret = regmap_bulk_read(st->map, reg, data, sizeof(data));
> > +	if (ret)
> > +		return ret;

> > +	*val = get_unaligned_be16(data);

In this case it will be be16_to_cpu() instead (from asm/byteorder.h).

> > +	if (*val == INV_ICM42607_DATA_INVALID)
> > +		return -EINVAL;
> > +
> > +	return 0;
> > +}

-- 
With Best Regards,
Andy Shevchenko





More information about the Linux-rockchip mailing list