Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH] Input: tsc2007 - fix resistance calculation when A/D value is saturated
@ 2026-05-11  5:40 Yuki Horii
  2026-05-12  0:04 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Yuki Horii @ 2026-05-11  5:40 UTC (permalink / raw)
  To: dmitry.torokhov; +Cc: andreas, clamor95, linux-input, yuuki198708, Yuki Horii

The A/D conversion sequence starts with reading the Y position
immediately after the A/D converter is powered on. This makes
the Y position measurement more susceptible to instability due
to noise and mechanical bounce compared to the X position, and
may result in a saturated value (MAX_12BIT = 0xFFF).

While the Y position is not used in equation #1 of the datasheet
for touch resistance calculation, it is required for equation #2.
A saturated Y A/D value, like a saturated X A/D value, indicates
that the touch resistance calculation is invalid.

Only the saturation of the X A/D value was checked, while the
saturation of the Y A/D value was not. Additionally, modifying
tc->x directly had an unintended side effect of corrupting the
caller's data.

The function now returns 0 when either X or Y A/D value is
saturated to indicate that the touch resistance calculation
is invalid.

Signed-off-by: Yuki Horii <horiiyuk@ishida.co.jp>
---
 drivers/input/touchscreen/tsc2007_core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/input/touchscreen/tsc2007_core.c b/drivers/input/touchscreen/tsc2007_core.c
index 524f14eb3da2..ce82163da4ff 100644
--- a/drivers/input/touchscreen/tsc2007_core.c
+++ b/drivers/input/touchscreen/tsc2007_core.c
@@ -71,9 +71,9 @@ u32 tsc2007_calculate_resistance(struct tsc2007 *tsc, struct ts_event *tc)
 {
 	u64 rt = 0;
 
-	/* range filtering */
-	if (tc->x == MAX_12BIT)
-		tc->x = 0;
+	/* invalidate touch resistance if X or Y coordinate is saturated */
+	if (tc->x == MAX_12BIT || tc->y == MAX_12BIT)
+		return 0;
 
 	if (likely(tc->x && tc->z1)) {
 		/* compute touch resistance using equation #1 */
-- 
2.51.0


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

end of thread, other threads:[~2026-05-12  3:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-11  5:40 [PATCH] Input: tsc2007 - fix resistance calculation when A/D value is saturated Yuki Horii
2026-05-12  0:04 ` sashiko-bot
2026-05-12  3:23   ` 堀井裕樹

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox