From: Ondrej Jirman <megi@xff.cz>
Pinephone Pro uses mpu6500.
Signed-off-by: Ondrej Jirman <megi@xff.cz>
Signed-off-by: Rudraksha Gupta <guptarud@gmail.com>
---
arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
index 65ee0b805034a4357a766d4f1f9efa2d4a843d77..21ff12ac5f6e52041f485c9f2702f5a15ee831f9 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
+++ b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
@@ -544,7 +544,13 @@ mpu6500@68 {
reg = <0x68>;
interrupt-parent = <&gpio1>;
interrupts = <RK_PC6 IRQ_TYPE_LEVEL_LOW>;
+ vdd-supply = <&vcc_1v8>;
vddio-supply = <&vcc_1v8>;
+
+ mount-matrix =
+ "1", "0", "0",
+ "0", "-1", "0",
+ "0", "0", "1";
};
};
--
2.51.0
Hi, On Sun, Sep 21, 2025 at 01:04:20AM -0700, Rudraksha Gupta via B4 Relay wrote: > From: Ondrej Jirman <megi@xff.cz> > > Pinephone Pro uses mpu6500. > > Signed-off-by: Ondrej Jirman <megi@xff.cz> > Signed-off-by: Rudraksha Gupta <guptarud@gmail.com> > --- > arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts > index 65ee0b805034a4357a766d4f1f9efa2d4a843d77..21ff12ac5f6e52041f485c9f2702f5a15ee831f9 100644 > --- a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts > +++ b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts > @@ -544,7 +544,13 @@ mpu6500@68 { > reg = <0x68>; > interrupt-parent = <&gpio1>; > interrupts = <RK_PC6 IRQ_TYPE_LEVEL_LOW>; > + vdd-supply = <&vcc_1v8>; > vddio-supply = <&vcc_1v8>; > + > + mount-matrix = > + "1", "0", "0", > + "0", "-1", "0", > + "0", "0", "1"; I'm not sure where you got this patch, but it's not from me (I know for sure I never did any mount-matrix testing/DT patches) and should not have my Signed-of-by. I have this in my tree https://codeberg.org/megi/linux/commit/d7cd2eab931e32fa94408a96d73b4e6c0616107a Which is: Signed-of-by: Leonardo G. Trombetta <lgtrombetta@gmx.com> And has different values on top of that and much more explanation. :) mount-matrix = "0", "1", "0", "-1", "0", "0", "0", "0", "1"; So I guess you'd need to provide a bit more information about how you tested/verified these values, or where you've got them from. See: https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/iio/mount-matrix.txt#L93 Looking at where the magnetometer is mounted, it's mounted on the bottom side of the PCB (U29 chip): https://xff.cz/dl/tmp/a0a36024d1ce9b15.png https://xff.cz/dl/tmp/8f9dce63f3a7f3f4.png Which means it would face from the PCB in the direction of the display and up towards the user who is looking at the display, due to the way PCB is mounted. From the datasheet: https://xff.cz/dl/tmp/6b163fbe4335e58e.png the relationship of the chip orientation to measured XYZ values. Putting it together https://xff.cz/dl/tmp/a17eec1488ea7705.png - Z increases downwards away from user looking at the phone display - Y increases to the left - X increases to the bottom of the display (towards USB-C connector) DT bindings state: - Magnetometers (compasses) have their world frame of reference relative to the geomagnetic field. The system orientation vis-a-vis the world is defined with respect to the local earth geomagnetic reference frame where (y) is in the ground plane and positive towards magnetic North, (x) is in the ground plane, perpendicular to the North axis and positive towards the East and (z) is perpendicular to the ground plane and positive upwards. ^^^ North: y > 0 (---------) ! ! ! ! ! ! ! ! > ! ! > North: x > 0 ! 1 2 3 ! > ! 4 5 6 ! ! 7 8 9 ! ! * 0 # ! (---------) Mount matrix in your patch just flips Y axis and leaves the rest as is, so that doesn't seem to match what bindings ask for at all. Just based on the PCB component placement and datasheets we should have: (small letters = DT bindings, big letters output from magnetometer) x = -Y y = -X z = -Z So that gives: mount-matrix = "0", "-1", "0", "-1", "0", "0", "0", "0", "-1"; I did a quick test (rotating the phone on the table with display facing up): - Y is highest when right edge of the phone faces north: in_magn_x_raw: -3074 in_magn_y_raw: -690 in_magn_z_raw: -1622 and lowest when pointing south in_magn_x_raw: -3569 in_magn_y_raw: -2052 in_magn_z_raw: -1824 (X is roughly the same) so that matches x = Y - X is highest when top edge of the phone faces north: in_magn_x_raw: -3990 in_magn_y_raw: -1287 in_magn_z_raw: -1677 and lowest when facing south in_magn_x_raw: -2553 in_magn_y_raw: -1314 in_magn_z_raw: -1624 (Y is roughly the same) y = X - Z is lower when display faces up in_magn_x_raw: -4083 in_magn_y_raw: -1179 in_magn_z_raw: -2436 and higher with display facing down in_magn_x_raw: -3999 in_magn_y_raw: -1584 in_magn_z_raw: 393 z = -Z So based on that mount-matrix should be: mount-matrix = "0", "1", "0", "1", "0", "0", "0", "0", "-1"; Go figure. :-D Best regards, o. > }; > }; > > > -- > 2.51.0 > >
Hello, > I'm not sure where you got this patch, but it's not from me (I know for sure > I never did any mount-matrix testing/DT patches) and should not have my > Signed-of-by. This is where I sourced each of the commits: - Add light/proximity sensor support - https://codeberg.org/megi/linux/commit/f171bc7013bc7ad3de9af817bfbcbfa548ebe01c - Add accelerometer sensor support - https://codeberg.org/megi/linux/commit/b0bb7633e073a6760fa213b8c4a78ea2e73c7bf1 - Add magnetometer sensor support - https://codeberg.org/megi/linux/commit/2f7e67f451f16eaf15b81aa1dbdf126d54927d35 - Add mount-matrix for magnetometer - https://codeberg.org/megi/linux/commit/d7cd2eab931e32fa94408a96d73b4e6c0616107a - Fix voltage threshold for volume down key - https://codeberg.org/megi/linux/commit/7c496a5cc27ed4e38b740f36c2d8b2c62f80ae54 I will add my sources to the cover letter moving forward. > Looking at where the magnetometer is mounted, it's mounted on the bottom side of > the PCB (U29 chip): > ... > So based on that mount-matrix should be: > > mount-matrix = > "0", "1", "0", > "1", "0", "0", > "0", "0", "-1"; Thanks, addressed in v3! Thanks, Rudraksha
Hi Rudraksha, On Sun, Sep 21, 2025 at 02:07:03PM -0700, Rudraksha Gupta wrote: > Hello, > > > I'm not sure where you got this patch, but it's not from me (I know for > sure > > I never did any mount-matrix testing/DT patches) and should not have my > > Signed-of-by. > > This is where I sourced each of the commits: > > - Add light/proximity sensor support > - https://codeberg.org/megi/linux/commit/f171bc7013bc7ad3de9af817bfbcbfa548ebe01c > - Add accelerometer sensor support > - https://codeberg.org/megi/linux/commit/b0bb7633e073a6760fa213b8c4a78ea2e73c7bf1 > - Add magnetometer sensor support > - https://codeberg.org/megi/linux/commit/2f7e67f451f16eaf15b81aa1dbdf126d54927d35 > - Add mount-matrix for magnetometer > - https://codeberg.org/megi/linux/commit/d7cd2eab931e32fa94408a96d73b4e6c0616107a > - Fix voltage threshold for volume down key > - https://codeberg.org/megi/linux/commit/7c496a5cc27ed4e38b740f36c2d8b2c62f80ae54 > > I will add my sources to the cover letter moving forward. > > > > > Looking at where the magnetometer is mounted, it's mounted on the bottom > side of > > the PCB (U29 chip): > > ... > > So based on that mount-matrix should be: > > > > mount-matrix = > > "0", "1", "0", > > "1", "0", "0", > > "0", "0", "-1"; > > Thanks, addressed in v3! Well, it's not clear this will work as expected. Someone should at least test it with some well working userspace sensor fusion program, that uses this information, (along with the mount matrix for accelerometer/gyro) for eg. compass feature or something like that. Also I don't see this matrix in v3 patch set. Did you test it? Any suggestions on what people actully use for sensor fusion on Linux? Regards, o. > > Thanks, > Rudraksha >
Hello Ondřej, > Well, it's not clear this will work as expected. Someone should at least test it > with some well working userspace sensor fusion program, that uses this > information, (along with the mount matrix for accelerometer/gyro) for eg. > compass feature or something like that. I'm not aware of any compass app on Linux at the moment > Also I don't see this matrix in v3 patch set. https://lore.kernel.org/all/20250921-ppp_light_accel_mag_vol-down-v3-4-7af6651f77e4@gmail.com/ + mount-matrix = + "0", "1", "0", + "1", "0", "0", + "0", "0", "-1"; > Did you test it? Any suggestions on what people actully use for sensor fusion on > Linux? Yep! I did brief testing, but I've put detailed testing below: For the accelerometer, the screen orientation works correctly now. Originally when tilting the ppp to the side, the screen would rotate to the correct side. However, when the phone was held regularly in your hand, the screen was upside down. With this patch series, it is no longer the case For the magnetometer, the command I ran was ``` #!/bin/sh DEVICE="/sys/bus/iio/devices/iio:device2" X=$(cat $DEVICE/in_magn_x_raw) Y=$(cat $DEVICE/in_magn_y_raw) Z=$(cat $DEVICE/in_magn_z_raw) X_MIN=$X; X_MAX=$X Y_MIN=$Y; Y_MAX=$Y Z_MIN=$Z; Z_MAX=$Z START_TIME=$(date +%s) while [ $(($(date +%s) - START_TIME)) -lt 10 ]; do X=$(cat $DEVICE/in_magn_x_raw) Y=$(cat $DEVICE/in_magn_y_raw) Z=$(cat $DEVICE/in_magn_z_raw) [ "$X" -lt "$X_MIN" ] && X_MIN=$X [ "$X" -gt "$X_MAX" ] && X_MAX=$X [ "$Y" -lt "$Y_MIN" ] && Y_MIN=$Y [ "$Y" -gt "$Y_MAX" ] && Y_MAX=$Y [ "$Z" -lt "$Z_MIN" ] && Z_MIN=$Z [ "$Z" -gt "$Z_MAX" ] && Z_MAX=$Z done echo "X_MIN: $X_MIN X_MAX: $X_MAX" echo "Y_MIN: $Y_MIN Y_MAX: $Y_MAX" echo "Z_MIN: $Z_MIN Z_MAX: $Z_MAX" ``` Tests: # phone on a flat surface top of the phone pointing north and bottom of phone pointing south: x (between -2379 and -2263), y (between 109 and 207), z (between -2340 and -2132) top of the phone pointing south and bottom of phone pointing north: x (between -1079 and -956), y (between -54 and 46), z (between -1831 and -1621) top of the phone pointing east and bottom of phone pointing west: x (between -1587 and -1473), y (between -448 and -339), z (between -1850 and -1602) top of the phone pointing west and bottom of phone pointing east: x (between -1426 and -1300), y (between 554 and 661), z (between -1917 and -1706) # the following tests are where the phone is tilted at a 45 degree angle and the top of phone is pointing up to the sky: top of the phone pointing north and bottom of phone pointing south: x (between -1300 and -1189), y (between 117 and 227), z (between -1819 and -1614) top of the phone pointing south and bottom of phone pointing north: x (between -539 and -422), y (between 23 and 143), z (between -1160 and -922) top of the phone pointing east and bottom of phone pointing west: x (between -1038 and -915), y (between -408 and -313), z (between -1570 and -1345) top of the phone pointing west and bottom of phone pointing east: x (between -965 and -849), y (between 540 and 641), z (between -1542 and -1336) # the following tests are where the phone is tilted at a 45 degree angle and the top of phone is pointing down to the ground: top of the phone pointing north and bottom of phone pointing south: x (between -2345 and -2237), y (between 80 and 189), z (between -1207 and -971) top of the phone pointing south and bottom of phone pointing north: x (between -1805 and -1691), y (between 5 and 112), z (between -1896 and -1651) top of the phone pointing east and bottom of phone pointing west: x (between -2127 and -2013), y (between 460 and 563), z (between -1621 and -1378) top of the phone pointing west and bottom of phone pointing east: x (between -2158 and -2054), y (between -376 and -264), z (between -1540 and -1262) I will put my testing in the commit itself moving forward Thanks, Rudraksha
On Sun, Sep 21, 2025 at 03:10:50PM +0200, megi xff wrote: > Hi, > > On Sun, Sep 21, 2025 at 01:04:20AM -0700, Rudraksha Gupta via B4 Relay wrote: > > From: Ondrej Jirman <megi@xff.cz> > > > > Pinephone Pro uses mpu6500. > > > > Signed-off-by: Ondrej Jirman <megi@xff.cz> > > Signed-off-by: Rudraksha Gupta <guptarud@gmail.com> > > --- > > arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts > > index 65ee0b805034a4357a766d4f1f9efa2d4a843d77..21ff12ac5f6e52041f485c9f2702f5a15ee831f9 100644 > > --- a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts > > +++ b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts > > @@ -544,7 +544,13 @@ mpu6500@68 { > > reg = <0x68>; > > interrupt-parent = <&gpio1>; > > interrupts = <RK_PC6 IRQ_TYPE_LEVEL_LOW>; > > + vdd-supply = <&vcc_1v8>; > > vddio-supply = <&vcc_1v8>; > > + > > + mount-matrix = > > + "1", "0", "0", > > + "0", "-1", "0", > > + "0", "0", "1"; > > I'm not sure where you got this patch, but it's not from me (I know for sure > I never did any mount-matrix testing/DT patches) and should not have my > Signed-of-by. Oh well, this is about the accelerometer. :) Anyway, this review should still be useful for the other patch in your series adding magnetometer support. You should add mount-matrix to that, too, since it's not an identity matrix apparently, which is the default without specifying mount-matrix in DT. Regards, o. > I have this in my tree https://codeberg.org/megi/linux/commit/d7cd2eab931e32fa94408a96d73b4e6c0616107a > Which is: > > Signed-of-by: Leonardo G. Trombetta <lgtrombetta@gmx.com> > > And has different values on top of that and much more explanation. :) > > mount-matrix = > "0", "1", "0", > "-1", "0", "0", > "0", "0", "1"; > > So I guess you'd need to provide a bit more information about how you > tested/verified these values, or where you've got them from. > > See: https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/iio/mount-matrix.txt#L93 > > Looking at where the magnetometer is mounted, it's mounted on the bottom side of > the PCB (U29 chip): > > https://xff.cz/dl/tmp/a0a36024d1ce9b15.png > https://xff.cz/dl/tmp/8f9dce63f3a7f3f4.png > > Which means it would face from the PCB in the direction of the display and up > towards the user who is looking at the display, due to the way PCB is mounted. > > From the datasheet: https://xff.cz/dl/tmp/6b163fbe4335e58e.png the relationship > of the chip orientation to measured XYZ values. > > Putting it together https://xff.cz/dl/tmp/a17eec1488ea7705.png > > > - Z increases downwards away from user looking at the phone display > - Y increases to the left > - X increases to the bottom of the display (towards USB-C connector) > > > DT bindings state: > > - Magnetometers (compasses) have their world frame of reference relative to the > geomagnetic field. The system orientation vis-a-vis the world is defined with > respect to the local earth geomagnetic reference frame where (y) is in the > ground plane and positive towards magnetic North, (x) is in the ground plane, > perpendicular to the North axis and positive towards the East and (z) is > perpendicular to the ground plane and positive upwards. > > ^^^ North: y > 0 > > (---------) > ! ! > ! ! > ! ! > ! ! > > ! ! > North: x > 0 > ! 1 2 3 ! > > ! 4 5 6 ! > ! 7 8 9 ! > ! * 0 # ! > (---------) > > Mount matrix in your patch just flips Y axis and leaves the rest as is, so that > doesn't seem to match what bindings ask for at all. > > Just based on the PCB component placement and datasheets we should have: > (small letters = DT bindings, big letters output from magnetometer) > > x = -Y > y = -X > z = -Z > > So that gives: > > mount-matrix = > "0", "-1", "0", > "-1", "0", "0", > "0", "0", "-1"; > > I did a quick test (rotating the phone on the table with display > facing up): > > - Y is highest when right edge of the phone faces north: > > in_magn_x_raw: -3074 > in_magn_y_raw: -690 > in_magn_z_raw: -1622 > > and lowest when pointing south > > in_magn_x_raw: -3569 > in_magn_y_raw: -2052 > in_magn_z_raw: -1824 > > (X is roughly the same) > > so that matches x = Y > > > - X is highest when top edge of the phone faces north: > > in_magn_x_raw: -3990 > in_magn_y_raw: -1287 > in_magn_z_raw: -1677 > > and lowest when facing south > > in_magn_x_raw: -2553 > in_magn_y_raw: -1314 > in_magn_z_raw: -1624 > > (Y is roughly the same) > > y = X > > - Z is lower when display faces up > > in_magn_x_raw: -4083 > in_magn_y_raw: -1179 > in_magn_z_raw: -2436 > > and higher with display facing down > > in_magn_x_raw: -3999 > in_magn_y_raw: -1584 > in_magn_z_raw: 393 > > z = -Z > > So based on that mount-matrix should be: > > mount-matrix = > "0", "1", "0", > "1", "0", "0", > "0", "0", "-1"; > > Go figure. :-D > > Best regards, > o. > > > > }; > > }; > > > > > > -- > > 2.51.0 > > > >
© 2016 - 2025 Red Hat, Inc.