Skip to contentSkip to conversation

Fix magnetometers on PinePhone

PATCH Applied Andrey Skvortsov 2 participants 10 messages Sep 8, 2024 – Nov 7, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Fix magnetometers on PinePhone

Introduce support for alternative magnetometer (AF8133J) used on new batches of PinePhones and define mount-matrix for both magnetometers.

Icenowy Zheng (1):
arm64: dts: sun50i-a64-pinephone: Add AF8133J to PinePhone

Shoji Keita (1):
arm64: dts: sun50i-a64-pinephone: Add mount-matrix for PinePhone
magnetometers

 .../dts/allwinner/sun50i-a64-pinephone.dtsi    | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/2 arm64: dts: sun50i-a64-pinephone: Add AF8133J to PinePhone

From: Icenowy Zheng <[email protected]>

New batches of PinePhones switched the magnetometer to AF8133J from LIS3MDL because lack of ST components.

Both chips use the same PB1 pin, but in different modes. LIS3MDL uses it as an gpio input to handle interrupt. AF8133J uses it as an gpio output as a reset signal.

It wasn't possible at runtime to enable both device tree nodes and detect supported sensor at probe time, because both drivers try to acquire the same gpio in different modes.

Device tree fixup will be done in firmware without introducing new board revision and new dts.

---
 .../boot/dts/allwinner/sun50i-a64-pinephone.dtsi     | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi +12 -0
index 6eab61a12cd8f..66fbb35a7fae9 100644
@@ -188,6 +188,18 @@ touchscreen@5d {
 &i2c1 {
 	status = "okay";
 
+	/* Alternative magnetometer */
+	af8133j: magnetometer@1c {
+		compatible = "voltafield,af8133j";
+		reg = <0x1c>;
+		reset-gpios = <&pio 1 1 GPIO_ACTIVE_LOW>;
+		avdd-supply = <&reg_dldo1>;
+		dvdd-supply = <&reg_dldo1>;
+
+		/* status will be fixed up in firmware */
+		status = "disabled";
+	};
+
 	/* Magnetometer */
 	lis3mdl: magnetometer@1e {
 		compatible = "st,lis3mdl-magn";
Signature · 1 line
2.45.2
#2 lore raw

Re: [PATCH 1/2] arm64: dts: sun50i-a64-pinephone: Add AF8133J to PinePhone

Quoted 10 lines · Andrey Skvortsov

From: Icenowy Zheng <[email protected]>

New batches of PinePhones switched the magnetometer to AF8133J from LIS3MDL because lack of ST components.

Both chips use the same PB1 pin, but in different modes. LIS3MDL uses it as an gpio input to handle interrupt. AF8133J uses it as an gpio output as a reset signal.

Quoted 6 lines

It wasn't possible at runtime to enable both device tree nodes and detect supported sensor at probe time, because both drivers try to acquire the same gpio in different modes.

Device tree fixup will be done in firmware without introducing new board revision and new dts.

FYI I've been working on an in-kernel prober [1] for such alternative components. This does not require firmware support.

[1] https://lore.kernel.org/all/[email protected]/

Quoted 34 lines
---
 .../boot/dts/allwinner/sun50i-a64-pinephone.dtsi     | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi +12 -1
index 6eab61a12cd8f..66fbb35a7fae9 100644
@@ -188,6 +188,18 @@ touchscreen@5d {
 &i2c1 {
        status = "okay";
 
+       /* Alternative magnetometer */
+       af8133j: magnetometer@1c {
+               compatible = "voltafield,af8133j";
+               reg = <0x1c>;
+               reset-gpios = <&pio 1 1 GPIO_ACTIVE_LOW>;
+               avdd-supply = <&reg_dldo1>;
+               dvdd-supply = <&reg_dldo1>;
+
+               /* status will be fixed up in firmware */
+               status = "disabled";
+       };
+
        /* Magnetometer */
        lis3mdl: magnetometer@1e {
                compatible = "st,lis3mdl-magn";
--

2.45.2

#3 lore raw

Re: [PATCH 1/2] arm64: dts: sun50i-a64-pinephone: Add AF8133J to PinePhone

Hi Chen-Yu Tsai,

Quoted 16 lines · Chen-Yu Tsai
Quoted 14 lines · Andrey Skvortsov

From: Icenowy Zheng <[email protected]>

New batches of PinePhones switched the magnetometer to AF8133J from LIS3MDL because lack of ST components.

Both chips use the same PB1 pin, but in different modes. LIS3MDL uses it as an gpio input to handle interrupt. AF8133J uses it as an gpio output as a reset signal.

It wasn't possible at runtime to enable both device tree nodes and detect supported sensor at probe time, because both drivers try to acquire the same gpio in different modes.

Quoted 7 lines
Quoted 2 lines

Device tree fixup will be done in firmware without introducing new board revision and new dts.

FYI I've been working on an in-kernel prober [1] for such alternative components. This does not require firmware support.

[1] https://lore.kernel.org/all/[email protected]/

Thank you for the information.

I've tried to use in-kernel prober from your v7 patchset [1] on top of -next and it worked without any changes to firmware.

Since there is still on-going review of your patches it looks like it's to early to submit my changes for review. But I'm ready to test your new patches.

[1] https://lore.kernel.org/all/[email protected]/

Signature · 2 lines
Best regards,
Andrey Skvortsov
#4 lore raw

Re: [PATCH 1/2] arm64: dts: sun50i-a64-pinephone: Add AF8133J to PinePhone

Quoted 28 lines · Andrey Skvortsov

Hi Chen-Yu Tsai,

Quoted 16 lines · Chen-Yu Tsai
Quoted 14 lines · Andrey Skvortsov

From: Icenowy Zheng <[email protected]>

New batches of PinePhones switched the magnetometer to AF8133J from LIS3MDL because lack of ST components.

Both chips use the same PB1 pin, but in different modes. LIS3MDL uses it as an gpio input to handle interrupt. AF8133J uses it as an gpio output as a reset signal.

It wasn't possible at runtime to enable both device tree nodes and detect supported sensor at probe time, because both drivers try to acquire the same gpio in different modes.

Quoted 7 lines
Quoted 2 lines

Device tree fixup will be done in firmware without introducing new board revision and new dts.

FYI I've been working on an in-kernel prober [1] for such alternative components. This does not require firmware support.

[1] https://lore.kernel.org/all/[email protected]/

Quoted 8 lines

Thank you for the information.

I've tried to use in-kernel prober from your v7 patchset [1] on top of -next and it worked without any changes to firmware.

Since there is still on-going review of your patches it looks like it's to early to submit my changes for review. But I'm ready to test your new patches.

FYI I'm open to either approach. If the firmware can do it, that is also fine. I don't know if it makes sense to have both disabled by default though? That would break existing users, but so would the in-kernel prober approach, which requires both components be marked as "fail-needs-probe", and also requires that the kernel driver be enabled.

In other words, I think the firmware approach is friendlier for existing users that have the original batches.

ChenYu

Quoted 6 lines

[1] https://lore.kernel.org/all/[email protected]/

--
Best regards,
Andrey Skvortsov

#5 lore raw

Re: [PATCH 1/2] arm64: dts: sun50i-a64-pinephone: Add AF8133J to PinePhone

Hi Chen-Yu Tsai,

Quoted 39 lines · Chen-Yu Tsai
Quoted 28 lines · Andrey Skvortsov

Hi Chen-Yu Tsai,

Quoted 16 lines · Chen-Yu Tsai
Quoted 14 lines · Andrey Skvortsov

From: Icenowy Zheng <[email protected]>

New batches of PinePhones switched the magnetometer to AF8133J from LIS3MDL because lack of ST components.

Both chips use the same PB1 pin, but in different modes. LIS3MDL uses it as an gpio input to handle interrupt. AF8133J uses it as an gpio output as a reset signal.

It wasn't possible at runtime to enable both device tree nodes and detect supported sensor at probe time, because both drivers try to acquire the same gpio in different modes.

Quoted 7 lines
Quoted 2 lines

Device tree fixup will be done in firmware without introducing new board revision and new dts.

FYI I've been working on an in-kernel prober [1] for such alternative components. This does not require firmware support.

[1] https://lore.kernel.org/all/[email protected]/

Quoted 8 lines

Thank you for the information.

I've tried to use in-kernel prober from your v7 patchset [1] on top of -next and it worked without any changes to firmware.

Since there is still on-going review of your patches it looks like it's to early to submit my changes for review. But I'm ready to test your new patches.

Quoted 7 lines

FYI I'm open to either approach. If the firmware can do it, that is also fine. I don't know if it makes sense to have both disabled by default though? That would break existing users, but so would the in-kernel prober approach, which requires both components be marked as "fail-needs-probe", and also requires that the kernel driver be enabled. In other words, I think the firmware approach is friendlier for existing users that have the original batches.

Current patches leave original magnetometer enabled as before. So only the new alternative magnetometer is disabled. Firmware prober will set the correct status. So you are right firmware approach is a bit nicer for existing users, nothing will change for them with any combination of kernel and firmware. Let's go with a firmware approach with current patches then, if nobody

But I like your in-kernel approach as well.
JFYI I've applied your v10 patches [1] on top of next-20241105 and retested it with patches for magnetometer. It's available here [2].

1. https://lore.kernel.org/lkml/[email protected]/#t
2. https://github.com/AndreySV/linux-stable/commits/in-kernel-hwprober-magnetometer/

Signature · 2 lines
Best regards,
Andrey Skvortsov
#6 lore raw

Re: [PATCH 1/2] arm64: dts: sun50i-a64-pinephone: Add AF8133J to PinePhone

Quoted 51 lines · Andrey Skvortsov

Hi Chen-Yu Tsai,

Quoted 39 lines · Chen-Yu Tsai
Quoted 28 lines · Andrey Skvortsov

Hi Chen-Yu Tsai,

Quoted 16 lines · Chen-Yu Tsai
Quoted 14 lines · Andrey Skvortsov

From: Icenowy Zheng <[email protected]>

New batches of PinePhones switched the magnetometer to AF8133J from LIS3MDL because lack of ST components.

Both chips use the same PB1 pin, but in different modes. LIS3MDL uses it as an gpio input to handle interrupt. AF8133J uses it as an gpio output as a reset signal.

It wasn't possible at runtime to enable both device tree nodes and detect supported sensor at probe time, because both drivers try to acquire the same gpio in different modes.

Quoted 7 lines
Quoted 2 lines

Device tree fixup will be done in firmware without introducing new board revision and new dts.

FYI I've been working on an in-kernel prober [1] for such alternative components. This does not require firmware support.

[1] https://lore.kernel.org/all/[email protected]/

Quoted 8 lines

Thank you for the information.

I've tried to use in-kernel prober from your v7 patchset [1] on top of -next and it worked without any changes to firmware.

Since there is still on-going review of your patches it looks like it's to early to submit my changes for review. But I'm ready to test your new patches.

Quoted 7 lines

FYI I'm open to either approach. If the firmware can do it, that is also fine. I don't know if it makes sense to have both disabled by default though? That would break existing users, but so would the in-kernel prober approach, which requires both components be marked as "fail-needs-probe", and also requires that the kernel driver be enabled. In other words, I think the firmware approach is friendlier for existing users that have the original batches.

Quoted 6 lines

Current patches leave original magnetometer enabled as before. So only the new alternative magnetometer is disabled. Firmware prober will set the correct status. So you are right firmware approach is a bit nicer for existing users, nothing will change for them with any combination of kernel and firmware. Let's go with a firmware approach with current patches then, if nobody

If?

I'll wait a day before applying this patch then.

ChenYu

Quoted 10 lines

But I like your in-kernel approach as well.
JFYI I've applied your v10 patches [1] on top of next-20241105 and retested it with patches for magnetometer. It's available here [2].

1. https://lore.kernel.org/lkml/[email protected]/#t
2. https://github.com/AndreySV/linux-stable/commits/in-kernel-hwprober-magnetometer/

--
Best regards,
Andrey Skvortsov

#7 lore raw

Re: [PATCH 1/2] arm64: dts: sun50i-a64-pinephone: Add AF8133J to PinePhone

Hi,

Quoted 13 lines · Chen-Yu Tsai
Quoted 10 lines · Andrey Skvortsov
Quoted 9 lines

FYI I'm open to either approach. If the firmware can do it, that is also fine. I don't know if it makes sense to have both disabled by default though? That would break existing users, but so would the in-kernel prober approach, which requires both components be marked as "fail-needs-probe", and also requires that the kernel driver be enabled. In other words, I think the firmware approach is friendlier for existing users that have the original batches.

Quoted 8 lines
Quoted 6 lines

Current patches leave original magnetometer enabled as before. So only the new alternative magnetometer is disabled. Firmware prober will set the correct status. So you are right firmware approach is a bit nicer for existing users, nothing will change for them with any combination of kernel and firmware. Let's go with a firmware approach with current patches then, if nobody

If?

if no one has anything against that.

Quoted 1 line

I'll wait a day before applying this patch then.

Sure, thanks.

Signature · 2 lines
Best regards,
Andrey Skvortsov
#8 lore raw

PATCH 2/2 arm64: dts: sun50i-a64-pinephone: Add mount-matrix for PinePhone magnetometers

In reply to Andrey Skvortsov

From: Shoji Keita <[email protected]>

For lis3mdl, values are based on datasheet and PCB drawing and tested on a real device.

For af8133j, values are from testing on a real device.

---
 arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi +6 -0
index 66fbb35a7fae9..d35d747292ce6 100644
@@ -195,6 +195,9 @@ af8133j: magnetometer@1c {
 		reset-gpios = <&pio 1 1 GPIO_ACTIVE_LOW>;
 		avdd-supply = <&reg_dldo1>;
 		dvdd-supply = <&reg_dldo1>;
+		mount-matrix = "0", "-1", "0",
+				"-1", "0", "0",
+				"0", "0", "-1";
 
 		/* status will be fixed up in firmware */
 		status = "disabled";
@@ -206,6 +209,9 @@ lis3mdl: magnetometer@1e {
 		reg = <0x1e>;
 		vdd-supply = <&reg_dldo1>;
 		vddio-supply = <&reg_dldo1>;
+		mount-matrix = "0", "1", "0",
+				"-1", "0", "0",
+				"0", "0", "1";
 	};
 
 	/* Light/proximity sensor */
Signature · 1 line
2.45.2
Applied
#9 lore raw
In reply to Andrey Skvortsov
Quoted 11 lines · Andrey Skvortsov

Introduce support for alternative magnetometer (AF8133J) used on new batches of PinePhones and define mount-matrix for both magnetometers.

Icenowy Zheng (1):
arm64: dts: sun50i-a64-pinephone: Add AF8133J to PinePhone

Shoji Keita (1):
arm64: dts: sun50i-a64-pinephone: Add mount-matrix for PinePhone
magnetometers

[...]

Applied to dt-for-6.13 in [email protected]:linux-sunxi/linux-sunxi.git, thanks!

[1/2] arm64: dts: sun50i-a64-pinephone: Add AF8133J to PinePhone

      commit: 193b199a925b04e2d9bc9dde8bb63f6d55483b7d
[2/2] arm64: dts: sun50i-a64-pinephone: Add mount-matrix for PinePhone magnetometers
      commit: 844c35cea6b2d36608c3026c7d29a4f5350b7ad9

Best regards,

Signature · 1 line
Chen-Yu Tsai <[email protected]>