devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] Upstreaming Pinephone Pro Patches
@ 2025-09-21  8:04 Rudraksha Gupta via B4 Relay
  2025-09-21  8:04 ` [PATCH v2 1/5] arm64: dts: rk3399-pinephone-pro: Add light/proximity sensor support Rudraksha Gupta via B4 Relay
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Rudraksha Gupta via B4 Relay @ 2025-09-21  8:04 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner
  Cc: devicetree, linux-arm-kernel, linux-rockchip, linux-kernel,
	Rudraksha Gupta, Ondrej Jirman, Leonardo G. Trombetta

Throughout the years, many have contributed to the Pinephone Pro (pro)
development. Unfortunately, these patches are scattered around various
repositories in different states.

I will be attempting to upstream these patches. I will start off with the
following small series:
- Add light/proximity sensor support
- Add accelerometer sensor support
- Add magnetometer sensor support
- Add mount-matrix for magnetometer
- Fix voltage threshold for volume down key

Signed-off-by: Rudraksha Gupta <guptarud@gmail.com>
---
Changes in v2:
- remove usb-typec node in dts from light/proximity sensor patch
- Link to v1: https://lore.kernel.org/r/20250920-ppp_light_accel_mag_vol-down-v1-0-c8bbcd3e2e94@gmail.com

---
Leonardo G. Trombetta (1):
      arm64: dts: rk3399-pinephone-pro: Add mount-matrix for magnetometer

Ondrej Jirman (4):
      arm64: dts: rk3399-pinephone-pro: Add light/proximity sensor support
      arm64: dts: rk3399-pinephone-pro: Add accelerometer sensor support
      arm64: dts: rk3399-pinephone-pro: Add magnetometer sensor support
      arm64: dts: rk3399-pinephone-pro: Fix voltage threshold for volume down key

 .../boot/dts/rockchip/rk3399-pinephone-pro.dts     | 40 +++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
---
base-commit: f83ec76bf285bea5727f478a68b894f5543ca76e
change-id: 20250920-ppp_light_accel_mag_vol-down-817c84fdae8d

Best regards,
-- 
Rudraksha Gupta <guptarud@gmail.com>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 1/5] arm64: dts: rk3399-pinephone-pro: Add light/proximity sensor support
  2025-09-21  8:04 [PATCH v2 0/5] Upstreaming Pinephone Pro Patches Rudraksha Gupta via B4 Relay
@ 2025-09-21  8:04 ` Rudraksha Gupta via B4 Relay
  2025-09-21  8:04 ` [PATCH v2 2/5] arm64: dts: rk3399-pinephone-pro: Add accelerometer " Rudraksha Gupta via B4 Relay
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Rudraksha Gupta via B4 Relay @ 2025-09-21  8:04 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner
  Cc: devicetree, linux-arm-kernel, linux-rockchip, linux-kernel,
	Rudraksha Gupta, Ondrej Jirman

From: Ondrej Jirman <megi@xff.cz>

Pinephone Pro uses STK3311

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 | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
index 6f97e57f36f5599f4027a0f3db98bcbc69cef5e5..65ee0b805034a4357a766d4f1f9efa2d4a843d77 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
+++ b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
@@ -520,6 +520,17 @@ touchscreen@14 {
 		touchscreen-size-x = <720>;
 		touchscreen-size-y = <1440>;
 	};
+
+	light-sensor@48 {
+		compatible = "sensortek,stk3311";
+		reg = <0x48>;
+		interrupt-parent = <&gpio4>;
+		interrupts = <RK_PD3 IRQ_TYPE_EDGE_FALLING>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&stk3311_int>;
+		vdd-supply = <&vcc_3v0>;
+		leda-supply = <&vcc_3v0>;
+	};
 };
 
 &i2c4 {
@@ -689,6 +700,12 @@ vcc1v8_codec_en: vcc1v8-codec-en {
 		};
 	};
 
+	stk3311 {
+		stk3311_int: stk3311-int {
+			rockchip,pins = <4 RK_PD3 RK_FUNC_GPIO &pcfg_input_pull_up>;
+		};
+	};
+
 	wireless-bluetooth {
 		bt_wake_pin: bt-wake-pin {
 			rockchip,pins = <2 RK_PD2 RK_FUNC_GPIO &pcfg_pull_none>;

-- 
2.51.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 2/5] arm64: dts: rk3399-pinephone-pro: Add accelerometer sensor support
  2025-09-21  8:04 [PATCH v2 0/5] Upstreaming Pinephone Pro Patches Rudraksha Gupta via B4 Relay
  2025-09-21  8:04 ` [PATCH v2 1/5] arm64: dts: rk3399-pinephone-pro: Add light/proximity sensor support Rudraksha Gupta via B4 Relay
@ 2025-09-21  8:04 ` Rudraksha Gupta via B4 Relay
  2025-09-21 13:10   ` Ondřej Jirman
  2025-09-21  8:04 ` [PATCH v2 3/5] arm64: dts: rk3399-pinephone-pro: Add magnetometer " Rudraksha Gupta via B4 Relay
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Rudraksha Gupta via B4 Relay @ 2025-09-21  8:04 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner
  Cc: devicetree, linux-arm-kernel, linux-rockchip, linux-kernel,
	Rudraksha Gupta, Ondrej Jirman

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



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 3/5] arm64: dts: rk3399-pinephone-pro: Add magnetometer sensor support
  2025-09-21  8:04 [PATCH v2 0/5] Upstreaming Pinephone Pro Patches Rudraksha Gupta via B4 Relay
  2025-09-21  8:04 ` [PATCH v2 1/5] arm64: dts: rk3399-pinephone-pro: Add light/proximity sensor support Rudraksha Gupta via B4 Relay
  2025-09-21  8:04 ` [PATCH v2 2/5] arm64: dts: rk3399-pinephone-pro: Add accelerometer " Rudraksha Gupta via B4 Relay
@ 2025-09-21  8:04 ` Rudraksha Gupta via B4 Relay
  2025-09-21  8:04 ` [PATCH v2 4/5] arm64: dts: rk3399-pinephone-pro: Add mount-matrix for magnetometer Rudraksha Gupta via B4 Relay
  2025-09-21  8:04 ` [PATCH v2 5/5] arm64: dts: rk3399-pinephone-pro: Fix voltage threshold for volume down key Rudraksha Gupta via B4 Relay
  4 siblings, 0 replies; 13+ messages in thread
From: Rudraksha Gupta via B4 Relay @ 2025-09-21  8:04 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner
  Cc: devicetree, linux-arm-kernel, linux-rockchip, linux-kernel,
	Rudraksha Gupta, Ondrej Jirman

From: Ondrej Jirman <megi@xff.cz>

Pinephone Pro uses AF8133J.

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 | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
index 21ff12ac5f6e52041f485c9f2702f5a15ee831f9..266a08540dd0fe099319ec703bb0828c8c5c2c25 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
+++ b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
@@ -554,6 +554,16 @@ mpu6500@68 {
 	};
 };
 
+&i2c4 {
+	af8133j: compass@1c {
+		compatible = "voltafield,af8133j";
+		reg = <0x1c>;
+		reset-gpios = <&gpio1 RK_PA1 GPIO_ACTIVE_LOW>;
+		avdd-supply = <&vcc_3v0>;
+		dvdd-supply = <&vcc_1v8>;
+	};
+};
+
 &io_domains {
 	bt656-supply = <&vcc1v8_dvp>;
 	audio-supply = <&vcca1v8_codec>;

-- 
2.51.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 4/5] arm64: dts: rk3399-pinephone-pro: Add mount-matrix for magnetometer
  2025-09-21  8:04 [PATCH v2 0/5] Upstreaming Pinephone Pro Patches Rudraksha Gupta via B4 Relay
                   ` (2 preceding siblings ...)
  2025-09-21  8:04 ` [PATCH v2 3/5] arm64: dts: rk3399-pinephone-pro: Add magnetometer " Rudraksha Gupta via B4 Relay
@ 2025-09-21  8:04 ` Rudraksha Gupta via B4 Relay
  2025-09-21  8:04 ` [PATCH v2 5/5] arm64: dts: rk3399-pinephone-pro: Fix voltage threshold for volume down key Rudraksha Gupta via B4 Relay
  4 siblings, 0 replies; 13+ messages in thread
From: Rudraksha Gupta via B4 Relay @ 2025-09-21  8:04 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner
  Cc: devicetree, linux-arm-kernel, linux-rockchip, linux-kernel,
	Rudraksha Gupta, Leonardo G. Trombetta

From: "Leonardo G. Trombetta" <lgtrombetta@gmx.com>

After experimenting with the magnetometer on the Pinephone Pro I found
out the mount-matrix currently reported by the AF8133J driver is just
the identity matrix (no rotation), which is wrong. It would seem to me
that there is currently no `mount-matrix` info and that's why the driver
reports a trivial answer. As far as I can tell from my tests, a 90
degree clockwise rotation in the XY plane would align it properly.

Signed-off-by: Leonardo G. Trombetta <lgtrombetta@gmx.com>
Signed-off-by: Rudraksha Gupta <guptarud@gmail.com>
---
 arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
index 266a08540dd0fe099319ec703bb0828c8c5c2c25..0a4121b05d36c5a7e05eddbd3514a11ae4f7d3eb 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
+++ b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
@@ -561,6 +561,11 @@ af8133j: compass@1c {
 		reset-gpios = <&gpio1 RK_PA1 GPIO_ACTIVE_LOW>;
 		avdd-supply = <&vcc_3v0>;
 		dvdd-supply = <&vcc_1v8>;
+
+		mount-matrix =
+			"0", "1", "0",
+			"-1", "0", "0",
+			"0", "0", "1";
 	};
 };
 

-- 
2.51.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 5/5] arm64: dts: rk3399-pinephone-pro: Fix voltage threshold for volume down key
  2025-09-21  8:04 [PATCH v2 0/5] Upstreaming Pinephone Pro Patches Rudraksha Gupta via B4 Relay
                   ` (3 preceding siblings ...)
  2025-09-21  8:04 ` [PATCH v2 4/5] arm64: dts: rk3399-pinephone-pro: Add mount-matrix for magnetometer Rudraksha Gupta via B4 Relay
@ 2025-09-21  8:04 ` Rudraksha Gupta via B4 Relay
  2025-09-21 11:20   ` Ondřej Jirman
  4 siblings, 1 reply; 13+ messages in thread
From: Rudraksha Gupta via B4 Relay @ 2025-09-21  8:04 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner
  Cc: devicetree, linux-arm-kernel, linux-rockchip, linux-kernel,
	Rudraksha Gupta, Ondrej Jirman

From: Ondrej Jirman <megi@xff.cz>

U-Boot and Linux use different algorithms for determining voltage ranges
for comparison. Pick value that will work with both.

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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
index 0a4121b05d36c5a7e05eddbd3514a11ae4f7d3eb..4e6df664d780ed4798015db6b2fe79bf7c4e4c00 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
+++ b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
@@ -46,7 +46,7 @@ button-up {
 		button-down {
 			label = "Volume Down";
 			linux,code = <KEY_VOLUMEDOWN>;
-			press-threshold-microvolt = <600000>;
+			press-threshold-microvolt = <400000>;
 		};
 	};
 

-- 
2.51.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 5/5] arm64: dts: rk3399-pinephone-pro: Fix voltage threshold for volume down key
  2025-09-21  8:04 ` [PATCH v2 5/5] arm64: dts: rk3399-pinephone-pro: Fix voltage threshold for volume down key Rudraksha Gupta via B4 Relay
@ 2025-09-21 11:20   ` Ondřej Jirman
  2025-09-21 21:06     ` Rudraksha Gupta
  0 siblings, 1 reply; 13+ messages in thread
From: Ondřej Jirman @ 2025-09-21 11:20 UTC (permalink / raw)
  To: guptarud
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner,
	devicetree, linux-arm-kernel, linux-rockchip, linux-kernel

Hi,

On Sun, Sep 21, 2025 at 01:04:23AM -0700, Rudraksha Gupta via B4 Relay wrote:
> From: Ondrej Jirman <megi@xff.cz>
> 
> U-Boot and Linux use different algorithms for determining voltage ranges
> for comparison. Pick value that will work with both.
> 
> 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 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
> index 0a4121b05d36c5a7e05eddbd3514a11ae4f7d3eb..4e6df664d780ed4798015db6b2fe79bf7c4e4c00 100644
> --- a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
> +++ b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
> @@ -46,7 +46,7 @@ button-up {
>  		button-down {
>  			label = "Volume Down";
>  			linux,code = <KEY_VOLUMEDOWN>;
> -			press-threshold-microvolt = <600000>;
> +			press-threshold-microvolt = <400000>;

This is fixes the issue accidentally...

According to the schematic the actual threshold is 1.8V*(2/12) = 0.3V :)

  https://xff.cz/dl/tmp/f1410ee03fac4c5b.png

Linux adc-keys driver uses the "closest to the threshold voltage key wins"
algorithm.

  https://elixir.bootlin.com/linux/v6.16.8/source/drivers/input/keyboard/adc-keys.c#L32

U-Boot uses the same algorithm implemented differently:

  https://elixir.bootlin.com/u-boot/v2025.10-rc4/source/drivers/button/button-adc.c#L97

So my description in the commit message is wrong.

For the current volume up/down key voltage DT "thresholds" the actual threshold
used by the driver to determine which key will be detected will be:

  (100 + (600 - 100)/2) = 350 mV

So unless you press the key very lightly, a lot of the time adc voltage will be
below 350 mV for the Volume Down key and will be misdetected as Volume Up key
press.

Here a few volume down key presses on my PPP:

[   32.567143] volkey val 1791
[   32.671337] volkey val 1791
[   32.775266] volkey val 1791
[   32.879208] volkey val 1791
[   32.983109] volkey val 1791
[   33.086836] volkey val 1791
[   33.191116] volkey val 300
[   33.295158] volkey val 298 <-----
[   33.399351] volkey val 1791
[   33.503339] volkey val 1792
[   33.607128] volkey val 1792
[   33.711296] volkey val 1791
[   33.815307] volkey val 1791
[   33.919333] volkey val 1791
[   34.023392] volkey val 311
[   34.127329] volkey val 305
[   34.231124] volkey val 1791
[   34.335390] volkey val 1791
[   34.439303] volkey val 1791
[   34.543256] volkey val 1791

On my other Pinephone Pro it goes down even to 293 mV when the button is pressed harder.

It doesn't help that the Volume Up button threshold in DT is set incorrectly, too.
It should be 2mV and not 100mV.

So the correct fix here is to change both button thresholds to:

  Volume Down

    press-threshold-microvolt = <300000>;

  Volume Up

    press-threshold-microvolt = <2000>;

To match the schematic. Then the threshold/decision voltage will become ~150mV,
which works fine according to my tests.

Best regards,
	o.


>  		};
>  	};
>  
> 
> -- 
> 2.51.0
> 
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/5] arm64: dts: rk3399-pinephone-pro: Add accelerometer sensor support
  2025-09-21  8:04 ` [PATCH v2 2/5] arm64: dts: rk3399-pinephone-pro: Add accelerometer " Rudraksha Gupta via B4 Relay
@ 2025-09-21 13:10   ` Ondřej Jirman
  2025-09-21 13:23     ` Ondřej Jirman
  2025-09-21 21:07     ` Rudraksha Gupta
  0 siblings, 2 replies; 13+ messages in thread
From: Ondřej Jirman @ 2025-09-21 13:10 UTC (permalink / raw)
  To: guptarud
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner,
	devicetree, linux-arm-kernel, linux-rockchip, linux-kernel

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
> 
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/5] arm64: dts: rk3399-pinephone-pro: Add accelerometer sensor support
  2025-09-21 13:10   ` Ondřej Jirman
@ 2025-09-21 13:23     ` Ondřej Jirman
  2025-09-21 21:07     ` Rudraksha Gupta
  1 sibling, 0 replies; 13+ messages in thread
From: Ondřej Jirman @ 2025-09-21 13:23 UTC (permalink / raw)
  To: guptarud, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Heiko Stuebner, devicetree, linux-arm-kernel, linux-rockchip,
	linux-kernel

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
> > 
> > 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 5/5] arm64: dts: rk3399-pinephone-pro: Fix voltage threshold for volume down key
  2025-09-21 11:20   ` Ondřej Jirman
@ 2025-09-21 21:06     ` Rudraksha Gupta
  0 siblings, 0 replies; 13+ messages in thread
From: Rudraksha Gupta @ 2025-09-21 21:06 UTC (permalink / raw)
  To: Ondřej Jirman, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Heiko Stuebner, devicetree, linux-arm-kernel,
	linux-rockchip, linux-kernel

Hello,

 > So the correct fix here is to change both button thresholds to:
 >
 >   Volume Down
 >
 >     press-threshold-microvolt = <300000>;
 >
 >   Volume Up
 >
 >     press-threshold-microvolt = <2000>;

Thanks, addressed in v3!

Rudraksha


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/5] arm64: dts: rk3399-pinephone-pro: Add accelerometer sensor support
  2025-09-21 13:10   ` Ondřej Jirman
  2025-09-21 13:23     ` Ondřej Jirman
@ 2025-09-21 21:07     ` Rudraksha Gupta
  2025-09-22 16:59       ` Ondřej Jirman
  1 sibling, 1 reply; 13+ messages in thread
From: Rudraksha Gupta @ 2025-09-21 21:07 UTC (permalink / raw)
  To: Ondřej Jirman, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Heiko Stuebner, devicetree, linux-arm-kernel,
	linux-rockchip, linux-kernel

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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/5] arm64: dts: rk3399-pinephone-pro: Add accelerometer sensor support
  2025-09-21 21:07     ` Rudraksha Gupta
@ 2025-09-22 16:59       ` Ondřej Jirman
  2025-09-28  3:54         ` Rudraksha Gupta
  0 siblings, 1 reply; 13+ messages in thread
From: Ondřej Jirman @ 2025-09-22 16:59 UTC (permalink / raw)
  To: Rudraksha Gupta
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner,
	devicetree, linux-arm-kernel, linux-rockchip, linux-kernel

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
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/5] arm64: dts: rk3399-pinephone-pro: Add accelerometer sensor support
  2025-09-22 16:59       ` Ondřej Jirman
@ 2025-09-28  3:54         ` Rudraksha Gupta
  0 siblings, 0 replies; 13+ messages in thread
From: Rudraksha Gupta @ 2025-09-28  3:54 UTC (permalink / raw)
  To: Ondřej Jirman, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Heiko Stuebner, devicetree, linux-arm-kernel,
	linux-rockchip, linux-kernel

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


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-09-28  3:54 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-21  8:04 [PATCH v2 0/5] Upstreaming Pinephone Pro Patches Rudraksha Gupta via B4 Relay
2025-09-21  8:04 ` [PATCH v2 1/5] arm64: dts: rk3399-pinephone-pro: Add light/proximity sensor support Rudraksha Gupta via B4 Relay
2025-09-21  8:04 ` [PATCH v2 2/5] arm64: dts: rk3399-pinephone-pro: Add accelerometer " Rudraksha Gupta via B4 Relay
2025-09-21 13:10   ` Ondřej Jirman
2025-09-21 13:23     ` Ondřej Jirman
2025-09-21 21:07     ` Rudraksha Gupta
2025-09-22 16:59       ` Ondřej Jirman
2025-09-28  3:54         ` Rudraksha Gupta
2025-09-21  8:04 ` [PATCH v2 3/5] arm64: dts: rk3399-pinephone-pro: Add magnetometer " Rudraksha Gupta via B4 Relay
2025-09-21  8:04 ` [PATCH v2 4/5] arm64: dts: rk3399-pinephone-pro: Add mount-matrix for magnetometer Rudraksha Gupta via B4 Relay
2025-09-21  8:04 ` [PATCH v2 5/5] arm64: dts: rk3399-pinephone-pro: Fix voltage threshold for volume down key Rudraksha Gupta via B4 Relay
2025-09-21 11:20   ` Ondřej Jirman
2025-09-21 21:06     ` Rudraksha Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).