Re: [PATCH] iio: imu: inv_mpu6050: fix magnetometer scale of Y and Z axes
From: Jean-Baptiste Maneyrol
Date: Mon Oct 12 2026 - 04:21:07 EST
>inv_mpu_magn_get_scale() returns st->magn_raw_to_gauss[chan->address],
>where magn_raw_to_gauss[] holds one coefficient per axis, computed in
>inv_magn_init() from the per-axis factory sensitivity adjustment values
>(ASAX, ASAY, ASAZ) of the AK8975/AK8963 magnetometer.
>
>However INV_MPU9X50_MAGN_CHAN() never sets .address, so it is 0 for all
>three magnetometer channels. As a result the Y and Z channels report the
>scale computed from the X axis adjustment value, and userspace scales
>the Y and Z readings with the wrong per-axis calibration.
>
>Set .address to the axis index (0 for X, 1 for Y, 2 for Z) in the
>channel macro, matching the order used to fill magn_raw_to_gauss[].
>
>Fixes: b1392de06184 ("iio: imu: inv_mpu6050: add MPU925x magnetometer support")
>Assisted-by: LLM
>Signed-off-by: Arnav Kapoor <kapoorarnav43@xxxxxxxxx>
>---
>Compile-tested only (W=1); I don't have MPU9150/MPU925x hardware. I
>checked the built object: before this patch the X, Y and Z magnetometer
>channels all have .address == 0, after it they have 0, 1 and 2.
>
> drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 2 ++
> 1 file changed, 2 insertions(+)
>
>diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
>index 38c3f3b398d4..1614f49be66c 100644
>--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
>+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
>@@ -1576,6 +1576,8 @@ static const unsigned long inv_mpu_scan_masks[] = {
> .type = IIO_MAGN, \
> .modified = 1, \
> .channel2 = _chan2, \
>+ /* index of the axis in magn_raw_to_gauss[] */ \
>+ .address = (_chan2) - IIO_MOD_X, \
> .info_mask_separate = BIT(IIO_CHAN_INFO_SCALE) | \
> BIT(IIO_CHAN_INFO_RAW), \
> .scan_index = _index, \
>--
>2.53.0
>
Hello Arnav,
good catch indeed, thanks for the patch.
Acked-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@xxxxxxx>
Thanks,
JB