* [PATCH] iio: imu: inv_mpu6050: fix magnetometer scale of Y and Z axes
@ 2026-10-11 4:56 Arnav Kapoor
2026-10-12 7:50 ` Jean-Baptiste Maneyrol
0 siblings, 1 reply; 2+ messages in thread
From: Arnav Kapoor @ 2026-10-11 4:56 UTC (permalink / raw)
To: Jean-Baptiste Maneyrol, Jonathan Cameron
Cc: David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel, Arnav Kapoor
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@gmail.com>
---
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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] iio: imu: inv_mpu6050: fix magnetometer scale of Y and Z axes
2026-10-11 4:56 [PATCH] iio: imu: inv_mpu6050: fix magnetometer scale of Y and Z axes Arnav Kapoor
@ 2026-10-12 7:50 ` Jean-Baptiste Maneyrol
0 siblings, 0 replies; 2+ messages in thread
From: Jean-Baptiste Maneyrol @ 2026-10-12 7:50 UTC (permalink / raw)
To: Arnav Kapoor, Jonathan Cameron
Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel
>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@gmail.com>
>---
>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@tdk.com>
Thanks,
JB
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-12 8:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-11 4:56 [PATCH] iio: imu: inv_mpu6050: fix magnetometer scale of Y and Z axes Arnav Kapoor
2026-10-12 7:50 ` Jean-Baptiste Maneyrol
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®