Linux Input/HID development
 help / color / mirror / Atom feed
From: door_110@163.com
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	linux-input@vger.kernel.org, kairen@siemens.com
Cc: linux-kernel@vger.kernel.org, Kyle Manna <kyle.manna@fuel7.com>,
	stable@vger.kernel.org
Subject: [PATCH] Input: tca8418_keypad - fix debounce disable register configuration
Date: Fri, 23 Oct 2026 15:44:17 +0800	[thread overview]
Message-ID: <20261023074417.3078016-1-door_110@163.com> (raw)

From: RenKai <kairen@siemens.com>

The DEBOUNCE_DIS1..3 registers use active-high disable bits:
writing 0 enables input debounce, while writing 1 disables it.
The driver currently writes the active row and column masks directly
to these registers, disabling debounce on the configured pins.

Invert the masks so that configured pins have their debounce-disable
bits cleared and unused pins have them set. Mask DEBOUNCE_DIS3 with
0x03 to keep reserved bits [7:2] clear.

Use unsigned row and column masks when constructing the keypad-mode
configuration, avoiding the existing left shift of a negative value.

Verified register readback on hardware with a 4x4 keypad:
  DEBOUNCE_DIS1 (0x29): 0xf0
  DEBOUNCE_DIS2 (0x2a): 0xf0
  DEBOUNCE_DIS3 (0x2b): 0x03

These values clear the debounce-disable bits for ROW0..3 and COL0..3
and set them for the unused pins.

Fixes: fb6c721b69d4 ("Input: tca8418_keypad - initial driver release")
Cc: stable@vger.kernel.org
Signed-off-by: RenKai <kairen@siemens.com>
---
 drivers/input/keyboard/tca8418_keypad.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/input/keyboard/tca8418_keypad.c b/drivers/input/keyboard/tca8418_keypad.c
index 3bbd7e652533..92234df25397 100644
--- a/drivers/input/keyboard/tca8418_keypad.c
+++ b/drivers/input/keyboard/tca8418_keypad.c
@@ -234,21 +234,29 @@ static irqreturn_t tca8418_irq_handler(int irq, void *dev_id)
 static int tca8418_configure(struct tca8418_keypad *keypad_data,
 			     u32 rows, u32 cols)
 {
-	int reg, error = 0;
+	u32 row_mask, col_mask, reg;
+	int error = 0;
 
 	/* Assemble a mask for row and column registers */
-	reg  =  ~(~0 << rows);
-	reg += (~(~0 << cols)) << 8;
+	row_mask = (1U << rows) - 1;
+	col_mask = (1U << cols) - 1;
+	reg = row_mask | (col_mask << 8);
 
 	/* Set registers to keypad mode */
 	error |= tca8418_write_byte(keypad_data, REG_KP_GPIO1, reg);
 	error |= tca8418_write_byte(keypad_data, REG_KP_GPIO2, reg >> 8);
 	error |= tca8418_write_byte(keypad_data, REG_KP_GPIO3, reg >> 16);
 
-	/* Enable column debouncing */
-	error |= tca8418_write_byte(keypad_data, REG_DEBOUNCE_DIS1, reg);
-	error |= tca8418_write_byte(keypad_data, REG_DEBOUNCE_DIS2, reg >> 8);
-	error |= tca8418_write_byte(keypad_data, REG_DEBOUNCE_DIS3, reg >> 16);
+	/*
+	 * Enable debounce on used rows and columns only.
+	 * In DEBOUNCE_DIS registers: 0 = enabled, 1 = disabled.
+	 */
+	error |= tca8418_write_byte(keypad_data, REG_DEBOUNCE_DIS1,
+				    ~row_mask & 0xff);
+	error |= tca8418_write_byte(keypad_data, REG_DEBOUNCE_DIS2,
+				    ~col_mask & 0xff);
+	error |= tca8418_write_byte(keypad_data, REG_DEBOUNCE_DIS3,
+				    ~(col_mask >> 8) & 0x03);
 
 	if (error)
 		return error;
-- 
2.39.5


                 reply	other threads:[~2026-10-23  7:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261023074417.3078016-1-door_110@163.com \
    --to=door_110@163.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=kairen@siemens.com \
    --cc=kyle.manna@fuel7.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.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