phone-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] input: s6sy761: fix coordinate read bit shift
@ 2021-03-05  2:03 Caleb Connolly
  2021-03-05 11:55 ` Andi Shyti
  0 siblings, 1 reply; 3+ messages in thread
From: Caleb Connolly @ 2021-03-05  2:03 UTC (permalink / raw)
  To: caleb, andi, Dmitry Torokhov
  Cc: ~postmarketos/upstreaming, phone-devel, linux-input, linux-kernel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

The touch coordinates are read by shifting a value left by 3,
this is incorrect and effectively causes the coordinates to
be half of the correct value.

Shift by 4 bits instead to report the correct value.

This matches downstream examples, and has been confirmed on my
device (OnePlus 7 Pro).

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
---
 drivers/input/touchscreen/s6sy761.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/input/touchscreen/s6sy761.c b/drivers/input/touchscreen/s6sy761.c
index b63d7fdf0cd2..85a1f465c097 100644
--- a/drivers/input/touchscreen/s6sy761.c
+++ b/drivers/input/touchscreen/s6sy761.c
@@ -145,8 +145,8 @@ static void s6sy761_report_coordinates(struct s6sy761_data *sdata,
 	u8 major = event[4];
 	u8 minor = event[5];
 	u8 z = event[6] & S6SY761_MASK_Z;
-	u16 x = (event[1] << 3) | ((event[3] & S6SY761_MASK_X) >> 4);
-	u16 y = (event[2] << 3) | (event[3] & S6SY761_MASK_Y);
+	u16 x = (event[1] << 4) | ((event[3] & S6SY761_MASK_X) >> 4);
+	u16 y = (event[2] << 4) | (event[3] & S6SY761_MASK_Y);
 
 	input_mt_slot(sdata->input, tid);
 
-- 
2.29.2


-----BEGIN PGP SIGNATURE-----
Version: ProtonMail

wsFmBAEBCAAQBQJgQZF1CRAFgzErGV9ktgAKCRAFgzErGV9ktroYD/9RVSpG
TNuHm0cz8tS/oPFxPxO6Y35p3IF7I77hv0/Qy8CDBgyiJ2pZYP5dOgMPp7NV
MbIYMlN0sjXsAhcm81eho4qp7r5Fnv5YdRoe8QaueRaBVqG5xeip//sdYsdP
lkSLLJqM7caXOZ2QaVZp4w9v7PpZvyGTdDeBtyhVwrRpuEcZraFBGhyfv4Xf
WvU/hKj+0cnKt+WpmnEtwBkkX4PDqm2yXQASm5HrHli5z8XSlaTO55jFcQRP
+PcV/uBEVm9yhi4qYGEZYFZ526IpIcB4vKJi5h3fYro3ye66GfT+zb4HHwA/
cRoEFfRQ6TX1NUBeawi5l7LnAXP3w/RMQ9HnULjiFgLI1a63EsucXGnan2gt
N0Ig0nnbD/c0UG9dsm5u7POM1JhDrX184Bvh3WPb4t0XfYRCIQVB4S+ElG3n
KoPLMWjOzfSxFQcEK4axpOYePDGfbqMYTNy+g+m/aQa40OnYem2Tp6koIpz4
tzzHgpKlrUuMe571jZFO+eIwIxuu/5yaE1qBANfaCIemDWxX2dXEeaoFCTtu
LdqkxaQuxqPaZORlbuRHFkaFEsk2iWZ6eOSNo6dBQ+qxbIHFj8xYqYkZh5Hn
g7zP0UpHbcTEggFgGB0AM6n3+qQXVR+EwtKr7vBWiSAR6p2T87MNflFWbvk5
1fCR4mi79Teaafgunw==
=hTKj
-----END PGP SIGNATURE-----


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

* Re: [PATCH] input: s6sy761: fix coordinate read bit shift
  2021-03-05  2:03 [PATCH] input: s6sy761: fix coordinate read bit shift Caleb Connolly
@ 2021-03-05 11:55 ` Andi Shyti
  2021-03-05 17:54   ` Caleb Connolly
  0 siblings, 1 reply; 3+ messages in thread
From: Andi Shyti @ 2021-03-05 11:55 UTC (permalink / raw)
  To: Caleb Connolly
  Cc: Andi Shyti, Dmitry Torokhov, ~postmarketos/upstreaming,
	phone-devel, linux-input, linux-kernel

Hi Caleb,

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256

Please clean up the commit message.

> The touch coordinates are read by shifting a value left by 3,
> this is incorrect and effectively causes the coordinates to
> be half of the correct value.
> 
> Shift by 4 bits instead to report the correct value.
> 
> This matches downstream examples, and has been confirmed on my
> device (OnePlus 7 Pro).

The real reason is that from the register we get:

       byte 3             byte 2             byte 1
+--------+--------+ +-----------------+ +-----------------+
|        |        | |                 | |                 |
| X[3:0] | Y[3:0] | |     Y[11:4]     | |     X[11:4]     |
|        |        | |                 | |                 |
+--------+--------+ +-----------------+ +-----------------+

and the 12 bit values have to fit in a 16bit variable.

The upper 8 bits (in event[2] and event[1] need to be shifted
left by '4' and not by '3' in order to leave space to the lower
4 bits (in event[3]).

> 
> Signed-off-by: Caleb Connolly <caleb@connolly.tech>
> ---
>  drivers/input/touchscreen/s6sy761.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/s6sy761.c b/drivers/input/touchscreen/s6sy761.c
> index b63d7fdf0cd2..85a1f465c097 100644
> --- a/drivers/input/touchscreen/s6sy761.c
> +++ b/drivers/input/touchscreen/s6sy761.c
> @@ -145,8 +145,8 @@ static void s6sy761_report_coordinates(struct s6sy761_data *sdata,
>  	u8 major = event[4];
>  	u8 minor = event[5];
>  	u8 z = event[6] & S6SY761_MASK_Z;
> -	u16 x = (event[1] << 3) | ((event[3] & S6SY761_MASK_X) >> 4);
> -	u16 y = (event[2] << 3) | (event[3] & S6SY761_MASK_Y);
> +	u16 x = (event[1] << 4) | ((event[3] & S6SY761_MASK_X) >> 4);
> +	u16 y = (event[2] << 4) | (event[3] & S6SY761_MASK_Y);

the devil knows how that '3' has ended up there :)

Thanks for catching it!

Reviewed-by: Andi Shyti <andi@etezian.org>

Andi

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

* Re: [PATCH] input: s6sy761: fix coordinate read bit shift
  2021-03-05 11:55 ` Andi Shyti
@ 2021-03-05 17:54   ` Caleb Connolly
  0 siblings, 0 replies; 3+ messages in thread
From: Caleb Connolly @ 2021-03-05 17:54 UTC (permalink / raw)
  To: Andi Shyti
  Cc: Dmitry Torokhov, ~postmarketos/upstreaming, phone-devel,
	linux-input, linux-kernel

Hi Andi,

On 05/03/2021 11:55 am, Andi Shyti wrote:
> Hi Caleb,
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA256
> Please clean up the commit message.
oops! Sorry
>
>> The touch coordinates are read by shifting a value left by 3,
>> this is incorrect and effectively causes the coordinates to
>> be half of the correct value.
>>
>> Shift by 4 bits instead to report the correct value.
>>
>> This matches downstream examples, and has been confirmed on my
>> device (OnePlus 7 Pro).
> The real reason is that from the register we get:
>
>         byte 3             byte 2             byte 1
> +--------+--------+ +-----------------+ +-----------------+
> |        |        | |                 | |                 |
> | X[3:0] | Y[3:0] | |     Y[11:4]     | |     X[11:4]     |
> |        |        | |                 | |                 |
> +--------+--------+ +-----------------+ +-----------------+
>
> and the 12 bit values have to fit in a 16bit variable.
>
> The upper 8 bits (in event[2] and event[1] need to be shifted
> left by '4' and not by '3' in order to leave space to the lower
> 4 bits (in event[3]).
Thanks for clarifying, sorry for my rather naive commit message.
>> Signed-off-by: Caleb Connolly <caleb@connolly.tech>
>> ---
>>   drivers/input/touchscreen/s6sy761.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/input/touchscreen/s6sy761.c b/drivers/input/touchscreen/s6sy761.c
>> index b63d7fdf0cd2..85a1f465c097 100644
>> --- a/drivers/input/touchscreen/s6sy761.c
>> +++ b/drivers/input/touchscreen/s6sy761.c
>> @@ -145,8 +145,8 @@ static void s6sy761_report_coordinates(struct s6sy761_data *sdata,
>>   	u8 major = event[4];
>>   	u8 minor = event[5];
>>   	u8 z = event[6] & S6SY761_MASK_Z;
>> -	u16 x = (event[1] << 3) | ((event[3] & S6SY761_MASK_X) >> 4);
>> -	u16 y = (event[2] << 3) | (event[3] & S6SY761_MASK_Y);
>> +	u16 x = (event[1] << 4) | ((event[3] & S6SY761_MASK_X) >> 4);
>> +	u16 y = (event[2] << 4) | (event[3] & S6SY761_MASK_Y);
> the devil knows how that '3' has ended up there :)
>
> Thanks for catching it!
>
> Reviewed-by: Andi Shyti <andi@etezian.org>

Regards,

Caleb

>
> Andi


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

end of thread, other threads:[~2021-03-05 17:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05  2:03 [PATCH] input: s6sy761: fix coordinate read bit shift Caleb Connolly
2021-03-05 11:55 ` Andi Shyti
2021-03-05 17:54   ` Caleb Connolly

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