ARM Sunxi Platform Development
 help / color / mirror / Atom feed
From: Dragan Simic <dsimic@manjaro.org>
To: Dragan Simic <dsimic@manjaro.org>
Cc: "Chen-Yu Tsai" <wens@csie.org>,
	"Jernej Skrabec" <jernej.skrabec@gmail.com>,
	"Samuel Holland" <samuel@sholland.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Ondřej Jirman" <megi@xff.cz>
Subject: Re: [PATCH] arm64: dts: sun50i-a64-pinephone: Add mount matrix for accelerometer
Date: Wed, 18 Sep 2024 13:22:01 +0200	[thread overview]
Message-ID: <24da366b05406e4c16e88438938d6933@manjaro.org> (raw)
In-Reply-To: <ZuqyuvZ6tdzp5XSW@skv.local>

Hello Andrey,

On 2024-09-18 13:00, Andrey Skvortsov wrote:
> On 24-09-18 11:27, Dragan Simic wrote:
>>   arm64: dts: allwinner: pinephone: Add mount matrix to accelerometer
>> 
>> The patch description should be reworded like this, reflown into
>> proper line lengths, of course:
>> 
>>   The way InvenSense MPU-6050 accelerometer is mounted on the
>>   user-facing side of the Pine64 PinePhone mainboard requires
>>   the accelerometer's x- and y-axis to be swapped, and the
>>   direction of the accelerometer's y-axis to be inverted.
>> 
>>   Rectify this by adding a mount-matrix to the accelerometer
>>   definition in the PinePhone dtsi file.
>> 
>>   [andrey: Picked the patch description provided by dsimic]
>>   Fixes: 91f480d40942 ("arm64: dts: allwinner: Add initial support for
>> Pine64 PinePhone")
>>   Cc: stable@vger.kernel.org
> 
> Thanks for the commit description, it's much better, than original
> one.

Thanks, I'm glad that you like it.

>> Please note the Fixes tag, which will submit this bugfix patch
>> for inclusion into the long-term/stable kernels.
>> 
>> Also note that the patch description corrects the way inversion
>> of the axis direction is described, which should also be corrected
>> in the patch itself, as described further below.
>> 
>> After going through the InvenSense MPU-6050 datasheet, [1] the
>> MPU-6050 evaluation board user guide, the PinePhone schematic,
>> the PinePhone mainboard component placement, [2] and the kernel
>> bindings documentation for mount-matrix, [3] I can conslude that
>> only the direction of the accelerometer's y-axis is inverted,
>> while the direction of the z-axis remain unchanged, according
>> to the right-hand rule.
> 
> yes, it looks so on the first glance, but in MPU-6050 datasheet there
> is also following information:
> 
>  7.8 Three-Axis MEMS Accelerometer with 16-bit ADCs and Signal
>  Conditioning
> 
>  When the device is placed on a flat surface, it will measure
>  0g on the X- and Y-axes and +1g on the Z-axis.
> 
> So sensors reports positive acceleration values for Z-axis, when
> the gravity points to Z-minus. I see the same on device. positive
> values are returned, when screen and IC point upwards (not the center
> for gravity).
> 
> In device tree mount-matrix documentation [3] there is
> 
>  users would likely expect a value of 9.81 m/s^2 upwards along the (z)
>  axis, i.e. out of the screen when the device is held with its screen
>  flat on the planets surface.
> 
> According to that, it looks like Z-axis here has to be inverted.

Yes, reporting +1 g on the z-axis with the device remaining stationary
on a level surface is the normal behavior, and the returned positive
value actually goes along with the quoted description from the kernel
documentation.  The z-axis of the MPU-6050 goes upward and out of the
screen, the way the MPU-6050 is placed inside the PinePhone.

> It applies to other axes as well. And because of that I came from
> (only Y-axis is inverted)
> 
> x' = -y
> y' =  x
> z' =  z
> 
> to inverted solution (Y-axis is kept, but X and Z are inverted).
> 
> x' =  y
> y' = -x
> z' = -z
> 
> probably should put this information into commit description.

Wouldn't inverting the direction of the z-axis go against the
above-quoted description from the kernel documentation?

>> > > > Signed-off-by: Ondrej Jirman <megi@xff.cz>
>> > > > Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
>> > > > ---
>> > > >  arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi | 3 +++
>> > > >  1 file changed, 3 insertions(+)
>> > > >
>> > > > diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi
>> > > > b/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi
>> > > > index bc6af17e9267a..1da7506c38cd0 100644
>> > > > --- a/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi
>> > > > +++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi
>> > > > @@ -229,6 +229,9 @@ accelerometer@68 {
>> > > >  		interrupts = <7 5 IRQ_TYPE_EDGE_RISING>; /* PH5 */
>> > > >  		vdd-supply = <&reg_dldo1>;
>> > > >  		vddio-supply = <&reg_dldo1>;
>> > > > +		mount-matrix = "0", "1", "0",
>> > > > +				"-1", "0", "0",
>> > > > +				"0", "0", "-1";
>> > > >  	};
>> > > >  };
>> 
>> With the above-described analysis in mind, the mount-matrix
>> should be defined like this instead:
>> 
>> 		mount-matrix = "0", "1", "0",
>> 			       "-1", "0", "0",
>> 			       "0", "0", "1";
> 
> 
> x' =  0 * x + 1 * y + 0 * z =  y
> y' = -1 * x + 1 * y + 0 * z = -x
> z' =  0 * z + 0 * y + 1 * z =  z
> 
> your description says, that only Y-axis is inverted, but this matrix,
> imho, inverts original X axis as it was in original description.

The way it's specified, it actually swaps the x- and y-axis, and
inverts the direction of the y-axis, all that from the viewpoint
of the accelerometer, which matches the proposed patch description.
IOW, the description keeps the original names of the axes.

>> Please also note the line indentation that was changed a bit.
>> 
>> [1] https://rimgo.reallyaweso.me/vrBXQPq.png
>> [2] https://rimgo.reallyaweso.me/uTmT1pr.png
>> [3] 
>> https://www.kernel.org/doc/Documentation/devicetree/bindings/iio/mount-matrix.txt

  reply	other threads:[~2024-09-18 11:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-16 20:45 [PATCH] arm64: dts: sun50i-a64-pinephone: Add mount matrix for accelerometer Andrey Skvortsov
2024-09-16 21:08 ` Dragan Simic
2024-09-17 17:56   ` Andrey Skvortsov
2024-09-18  9:27     ` Dragan Simic
2024-09-18 10:02       ` Dragan Simic
2024-09-18 11:00       ` Andrey Skvortsov
2024-09-18 11:22         ` Dragan Simic [this message]
2024-09-18 11:27         ` Dragan Simic
2024-09-18 13:41           ` Andrey Skvortsov
2024-09-18 15:58             ` Andrey Skvortsov
2024-09-19 18:34               ` Dragan Simic
2024-09-21  7:44                 ` Dragan Simic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=24da366b05406e4c16e88438938d6933@manjaro.org \
    --to=dsimic@manjaro.org \
    --cc=conor+dt@kernel.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=megi@xff.cz \
    --cc=robh@kernel.org \
    --cc=samuel@sholland.org \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox