Skip to contentSkip to conversation

Input: tca8418_keypad - fix debounce disable register configuration

PATCH New [email protected] 1 participant 1 message Oct 23

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

PATCH 1/1 Input: tca8418_keypad - fix debounce disable register configuration

From: RenKai <[email protected]>

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")
---
 drivers/input/keyboard/tca8418_keypad.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/input/keyboard/tca8418_keypad.c +15 -7
index 3bbd7e652533..92234df25397 100644
@@ -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;
Signature · 1 line
2.39.5