Skip to content

Commit c68b44b

Browse files
NXP-CarlosSongjic23
authored andcommitted
iio: imu: fxos8700: fix swapped ACCEL and MAGN channels readback
Because ACCEL and MAGN channels data register base address is swapped the accelerometer and magnetometer channels readback is swapped. Fixes: 84e5ddd ("iio: imu: Add support for the FXOS8700 IMU") Signed-off-by: Carlos Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 429e1e8 commit c68b44b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

drivers/iio/imu/fxos8700_core.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,22 @@ static int fxos8700_get_data(struct fxos8700_data *data, int chan_type,
395395
{
396396
u8 base, reg;
397397
int ret;
398-
enum fxos8700_sensor type = fxos8700_to_sensor(chan_type);
399398

400-
base = type ? FXOS8700_OUT_X_MSB : FXOS8700_M_OUT_X_MSB;
399+
/*
400+
* Different register base addresses varies with channel types.
401+
* This bug hasn't been noticed before because using an enum is
402+
* really hard to read. Use an a switch statement to take over that.
403+
*/
404+
switch (chan_type) {
405+
case IIO_ACCEL:
406+
base = FXOS8700_OUT_X_MSB;
407+
break;
408+
case IIO_MAGN:
409+
base = FXOS8700_M_OUT_X_MSB;
410+
break;
411+
default:
412+
return -EINVAL;
413+
}
401414

402415
/* Block read 6 bytes of device output registers to avoid data loss */
403416
ret = regmap_bulk_read(data->regmap, base, data->buf,

0 commit comments

Comments
 (0)